Reputation: 12574
I have a WCF service that is being used to generate an XML file based on multiple different queries. In the end I am left with a complete XML file and I need a way of passing this back to the application that calls the method in my service. How can this be achieved using WCF?
I have tried a multitude of things such as sending back an XmlElement instead and populating that but when I do that the best I can do is pass back the root element and the contents inside that which isnt ideal as I lose the header which I need.
I tried this:
[OperationContract]
XmlElement Foo(MyType myType, string user);
string responseXMLString = getPointsResponse.ResponseHeader;
responseXMLString += getPointsResponse.ResponseRecords;
responseXMLString += getPointsResponse.ResponseFooter;
XmlDocument myDocument = new XmlDocument();
myDocument.LoadXml(responseXMLString);
return myDocument.DocumentElement;
This got me the whole document minus the header but I need the header. I want to send it all back as one object in XML format.
When I tried to send back an XML document I got a multitude of errors. When I also try to send it back as a string I get errors due to it having special chars and interfering with the SOAP response.
Any ideas?
Upvotes: 0
Views: 1993
Reputation: 31760
Out of the box WCF's http-based bindings all use soap to wrap the message payload except webHttpBinding, which enables support for RESTful-style interfaces.
Alternatively you could be looking at is how to achieve POX messaging with WCF, which can be found here: http://msdn.microsoft.com/en-us/library/aa395208(v=vs.90).aspx
UPDATE
REST support in WCF has well established procedures for security. For example, http://www.codeproject.com/Articles/149738/Basic-Authentication-on-a-WCF-REST-Service
Additionally I would say that you should look at your service contract composition, ie the number and types of operations exposed on your endpoint. It may be that this problem you face is a good enough reason to decouple the POX operations from the SOAP operations into their own service endpoint.
Upvotes: 1
Reputation: 2493
You can get it in string format using the following.
return myDocument.DocumentType.ToString() + myDocument.DocumentElement;
Upvotes: 0