I'm generating XML using XDocument in C#. Everything works fine except I always get auto generated string
XDocument doc = new XDocument(
new XDeclaration("1.0", "UTF-8", "yes"),
new XElement(aw+"ProviderUpdate",
//... more more here
)
);
return doc.ToString();
It always return something like this: How do I remove ?
<string xmlns="urn:Microsoft.Search.Registration.Response">
<ProviderUpdate xmlns="urn:Microsoft.Search.Registration.Response">
...
</ProviderUpdate>
</string>
I expected to be something like this:
<?xml version="1.0" encoding="utf-8"?>
<ProviderUpdate xmlns="urn:Microsoft.Search.Registration.Response">
...
</ProviderUpdate>
This is defined at top of my file:
[WebService(Namespace = "urn:Microsoft.Search.Registration.Response")]
But it does nothing else than change xmlns to a correct value.
The
string
element is the container for the value that you return from the web service. You can't return data that is not inside an element.If you want to return your own XML code from the web service, you shouldn't use the built in framework to generate the web service, but an HTTP handler so that you can return the response directly instead of wrapped inside a predetermined SOAP message.