WCF REST POST Method to pass List of strings
-
martes, 11 de enero de 2011 12:52
[WebInvoke(RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare, Method = "POST", UriTemplate = "searchCustomer")]
List<Customer> GetCustomer(SearchCustomer obj)
public class SearchCustomer
{
[DataMember]
List<string> customeNamer {get;set;};
[DataMember]
string country {get;set;};
}
When I post the xml and see in debug mode <Country>test</country> is passing to the service. But <CustomerName><string>Ronald</string></CustomerName> is not getting passed. Please let me know how to pass the list of strings to the REST method
Todas las respuestas
-
miércoles, 12 de enero de 2011 1:57
Ronald,
Your contract doesn't specify that you are passing a list of strings to the service. Rather it specifies that you are passing in a SearchCustomer instance. I thought that maybe you meant you want the service operation to return a list of strings, but again your contract doesn't specify that, it specifies that it returns a list of Customer instances. Can you please clarify what you are trying to do?
Thanks,
Michael Green
WCF Documentation Team -
miércoles, 12 de enero de 2011 6:28
Hi Michael,
I have to retrieve List of customer based on the search criteria. The Search criteria will contain a list of customer name and country name. The country name value which is posted as XML is passed to the service. But the List of customer name in xml is not getting passed to the service . I am using the below mentioned factory
Factory
="System.ServiceModel.Activation.WebServiceHostFactory"
Thanks
Ronald
-
miércoles, 12 de enero de 2011 7:16
Hi Michael
The issues is fixed using the following. I have to specify the collectionDataContract to pass the array of strings. And also I have to specify the order in the Data Memeber so that the ActivationFactory parses the xml properly.
[
CollectionDataContract(Name = "StringArray", Namespace = ContractConstants.CUSTOMERNAMESPACE)]
public class CustomerNameList : List<string>
{
public CustomerNameList() { }
public CustomerNameList(IEnumerable<string> strings) : base(strings) { }
}
[DataContract Namespace=ContractConstants.CUSTOMERNAMESPACE)]
public class SearchCustomer
{
[DataMember(order=0)]
CustomerNameList customeName {get;set;};
[DataMember(order=1)]
string country {get;set;};
}
- Marcado como respuesta Ronald Vimal miércoles, 12 de enero de 2011 7:16
-
martes, 20 de marzo de 2012 5:31im also facing the same issue ..
i tried defining collectiondatacontract but it didnt solve.. this is my datamember
[DataMember(Name = "CountryList", IsRequired = false, Order = 9)]
public List<string> CountryList{ get; set; }
can u help me in defining this,when trying to pass im getting as count = 0- Editado Kumar's sábado, 31 de marzo de 2012 6:34

