开发者

How can I send an XmlDocument to WCF service?

开发者 https://www.devze.com 2023-02-26 23:31 出处:网络
I need to pass an XmlDocument from ASP.Net to a WCF service - how can 开发者_StackOverflow中文版I do this?

I need to pass an XmlDocument from ASP.Net to a WCF service - how can 开发者_StackOverflow中文版I do this?

I think there is something to do in service contract and operation contract - I am new to this concept.

Thanks in advance.


stating this as an answer since I do not see the possibility to comment on the question.

it should be perfectly possible to send it across using a string (convert your xml to string and convert back inside your wcf service).


You can achieve this through XmlSerializer Class. This is all you need, please read: Using the XmlSerializer Class

This also satisfies the members being serialized as attributes and elements just like an Xml document should be.

Instead of:

<Person>
     <Name>Peyton Crow</Name>
</Person>

You can have the control of making the "Name" property as attribute:

<Person Name="Peyton Crow" />


If you only need the contents of the XmlDocument, one way is to declare an operation with an XmlNode parameter:

[OperationContract]
void MyOperation(XmlNode xml);

Then call it from the client as follows:

XmlDocument doc = ...
myService.MyOperation(doc.DocumentElement);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号