Passing IEnumerable <int> as a parameter for WCF service
I got xml:
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item>1</item>
<item>2</item>
<item>3</item>
</items>
And a wcf service contract:
[ServiceContract(Namespace = "", Name = "MyService", SessionMode = SessionMode.NotAllowed)]
public interface IMyService
{
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
void DoWork(IEnumerable<int> items);
}
Service binding is basic http. But when I try to publish this xml method for wcf, I get an error:
Unable to deserialize XML message with root name "items" and root namespace ""
What should the wcf method look like to work correctly with this xml?
Your service contract does not seem to be configured correctly.
I think you need to implement a "wrapper" class that defines a type structure that matches your XML.
For instance:
[XmlRoot("items")]
public class MyItems
{
[XmlElement("item")]
public List<int> Items { get; set; }
}
I just put together an application for quick testing and successfully tested the interface using your XML sample (through the SoapUI REST client).
Hi,
, xml. , , .
: http://www.codeproject.com/Articles/35982/REST-WCF-and-Streams-Getting-Rid-of-those-Names-Sp
, :
<?xml version="1.0" encoding="UTF-8"?>
<items xmlns="http://schemas.datacontract.org/2004/07/"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<item>1</item>
<item>2</item>
<item>3</item>
</items>
: . , :
[OperationContract]
[WebInvoke(BodyStyle =
WebMessageBodyStyle.Bare, Method = "POST", ResponseFormat = WebMessageFormat.Xml,)]
void DoWork(Stream data);
datacontract (: void DoWork(MyCustomDataContract data);) , :
WCF, datacontact?