Articles → WCF → List Converted To Array While Consuming WCF Service

List Converted To Array While Consuming WCF Service









[ServiceContract]
public interface IService1 {

	[OperationContract]
	string GetData(int value);

	[OperationContract]
	List < CompositeType > GetDataUsingDataContract(CompositeType composite);

	// TODO: Add your service operations here
}

// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType {
	bool boolValue = true;
	string stringValue = "Hello ";

	[DataMember]
	public bool BoolValue {
		get {
			return boolValue;
		}
		set {
			boolValue = value;
		}
	}

	[DataMember]
	public string StringValue {
		get {
			return stringValue;
		}
		set {
			stringValue = value;
		}
	}
}






public class Service1: IService1 {
	public string GetData(int value) {
		return string.Format("You entered: {0}", value);
	}

	public List < CompositeType > GetDataUsingDataContract(CompositeType composite) {
		return new List < CompositeType > ();
	}
}




Picture showing the console application code that is consuming the WCF service
Click to Enlarge


Solution




Picture showing the Configure Service Reference option in the context menu of the service reference
Click to Enlarge



Picture showing a window to convert collection type from array to List
Click to Enlarge



Picture showing the output of the List converted to array while consuming WCF service
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Friday, May 15, 2015

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250