Reputation: 4179
I am implementing a wcf restful service and I want to send a xml that contains list of a class to wcf service. Other arguments pass successfully to service but list comes empty. My xml;
<phoneBookWebServiceSearchResponse xmlns="http://callturksvc.alfion.com.tr">
<uniqueId>40</uniqueId>
<webServiceResponseType>SUCCESS</webServiceResponseType>
<clientQueryNo>0</clientQueryNo>
<responseMessage>SUCCESS</responseMessage>
<phoneBookList>
<phoneBook>
<cityCode>34</cityCode>
<cityName>İstanbul</cityName>
<districtName>Beşiktaş</districtName>
<firstName>Şuayp</firstName>
<lastModifiedDateTime>2013-01-28T15:30:36.925+02:00</lastModifiedDateTime>
<lastName>Çiçek</lastName>
<phoneBookTypeEnumValue>TURKCELL</phoneBookTypeEnumValue>
<phoneNumberText>5356875946</phoneNumberText>
</phoneBook>
</phoneBookList>
</phoneBookWebServiceSearchResponse>
And class that will handle this xml;
[DataContract(Name = "phoneBookWebServiceSearchResponse", Namespace ="http://callturksvc.alfion.com.tr")]
public class phoneBookWebServiceSearchResponse
{
[DataMember(Order = 1, Name = "uniqueId")]
public string uniqueId { get; set; }
[DataMember(Order = 2, Name = "webServiceResponseType")]
public string webServiceResponseType { get; set; }
[DataMember(Order = 3, Name = "clientQueryNo")]
public string clientQueryNo { get; set; }
[DataMember(Order = 4, Name = "responseMessage")]
public string responseMessage { get; set; }
[DataMember(Order = 5, Name = "phoneBookList")]
public phoneBookList phoneBookList { get; set; }
public phoneBookWebServiceSearchResponse()
{
uniqueId = string.Empty;
webServiceResponseType = string.Empty;
clientQueryNo = string.Empty;
responseMessage = string.Empty;
phoneBookList = new phoneBookList();
}
}
public class phoneBookList
{
[DataMember(Order = 1, Name = "phoneBook")]
public List<phoneBook> phoneBook { get; set; }
public phoneBookList()
{
phoneBook = new List<phoneBook>();
}
}
public class phoneBook
{
[DataMember(Order = 1, Name = "firstName")]
public string firstName { get; set; }
[DataMember(Order = 2, Name = "lastName")]
public string lastName { get; set; }
[DataMember(Order = 3, Name = "cityCode")]
public string cityCode { get; set; }
[DataMember(Order = 4, Name = "cityName")]
public string cityName { get; set; }
[DataMember(Order = 5, Name = "districtName")]
public string districtName { get; set; }
[DataMember(Order = 6, Name = "lastModifiedDateTime")]
public string lastModifiedDateTime { get; set; }
[DataMember(Order = 7, Name = "phoneBookTypeEnumValue")]
public string phoneBookTypeEnumValue { get; set; }
[DataMember(Order = 8, Name = "phoneNumberText")]
public string phoneNumberText { get; set; }
public phoneBook()
{
firstName = string.Empty;
lastName = string.Empty;
cityCode = string.Empty;
cityName = string.Empty;
districtName = string.Empty;
lastModifiedDateTime = string.Empty;
phoneBookTypeEnumValue = string.Empty;
phoneNumberText = string.Empty;
}
}
Response class is;
[DataContract(Name="CallTurkResponse", Namespace ="http://callturksvc.alfion.com.tr")]
public class CallTurkResponse
{
[DataMember(Name="responseMessage", Order=1)]
public string responseMessage { get; set; }
}
My service class is;
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Xml,
RequestFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "auth")]
CallTurkResponse Auth(phoneBookWebServiceSearchResponse res);
And finally my service is;
public CallTurkResponse Auth(phoneBookWebServiceSearchResponse res)
{
return new CallTurkResponse
{
responseMessage = "SUCCESS"
};
}
the problem is that when I sent xml request above, I get uniqueId, webServiceResponseType, clientQueryNo and responseMessage successfully in debugger. But phoneBookList comes to service empty.
Any solution?
Upvotes: 0
Views: 492
Reputation: 2258
Use IEnumerable
instead of List List<phoneBook>
.
Edit:
consider using IEnumerable
like an option. But also you need few updates to your code. At first, you should mark all classes with DataContract
Attribute providing the same namespace you have marked phoneBookWebServiceSearchResponse
class. Other way causes naming conflict in xml. Also it looks you don't need class phoneBookList
at all.
[DataContract(Name = "phoneBookWebServiceSearchResponse", Namespace = "http://callturksvc.alfion.com.tr")]
public class phoneBookWebServiceSearchResponse
{
[DataMember(Order = 1, Name = "uniqueId")]
public string uniqueId { get; set; }
[DataMember(Order = 2, Name = "webServiceResponseType")]
public string webServiceResponseType { get; set; }
[DataMember(Order = 3, Name = "clientQueryNo")]
public string clientQueryNo { get; set; }
[DataMember(Order = 4, Name = "responseMessage")]
public string responseMessage { get; set; }
[DataMember(Order = 5, Name = "phoneBookList")]
public List<phoneBook> phoneBookList { get; set; }
}
[DataContract(Name = "phoneBook", Namespace = "http://callturksvc.alfion.com.tr")]
public class phoneBook
{
[DataMember(Order = 1, Name = "firstName")]
public string firstName { get; set; }
[DataMember(Order = 2, Name = "lastName")]
public string lastName { get; set; }
[DataMember(Order = 3, Name = "cityCode")]
public string cityCode { get; set; }
[DataMember(Order = 4, Name = "cityName")]
public string cityName { get; set; }
[DataMember(Order = 5, Name = "districtName")]
public string districtName { get; set; }
[DataMember(Order = 6, Name = "lastModifiedDateTime")]
public string lastModifiedDateTime { get; set; }
[DataMember(Order = 7, Name = "phoneBookTypeEnumValue")]
public string phoneBookTypeEnumValue { get; set; }
[DataMember(Order = 8, Name = "phoneNumberText")]
public string phoneNumberText { get; set; }
}
Upvotes: 1