Reputation: 99
I have a problem with WCF request message namespaces. In every object I have a extra namespace prefix. How should I decorate a contract/object to get rid of these prefixes (want child nodes to inherit namespace form parent). In this case I am using a XmlSerializer. Current output (generated from SOAPUI, based on wsdl):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://somenamespace.com">
<soapenv:Header/>
<soapenv:Body>
<ns:InputObject>
<ns:Data>
<ns:property1>?</ns:property1>
<ns:property2>?</ns:property2>
</ns:Data>
</ns:InputObject>
</soapenv:Body>
</soapenv:Envelope>
Desired output:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://somenamespace.com">
<soapenv:Header/>
<soapenv:Body>
<ns:InputObject>
<Data>
<property1>?</property1>
<property2>?</property2>
</Data>
</ns:InputObject>
</soapenv:Body>
</soapenv:Envelope>
Upvotes: 0
Views: 1271
Reputation: 18517
It's not clear what are you trying to achieve however notes that the two XML you're showing are not equivalent (don't hesitate about prefix your first xml looks totally valid).
In the second one (which surely not accomplish your schema), <Data>
and <property>
elements are not in the same namespace as <InputObject>
, namespace inheritance work only for default namespace, if you use a namespace prefix you've to use it in every object.
If your goal is to avoid the use of prefix in <InputObject>
you've to put the xmlns="http://somenamespace.com"
in this tag, this way all <InputObject>
childs inherit the same namespace as its parent.
For example this xml that you shows in your question:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://somenamespace.com">
<soapenv:Header/>
<soapenv:Body>
<ns:InputObject>
<ns:Data>
<ns:property1>?</ns:property1>
<ns:property2>?</ns:property2>
</ns:Data>
</ns:InputObject>
</soapenv:Body>
</soapenv:Envelope>
is equivalent to:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<InputObject xmlns="http://somenamespace.com">
<Data>
<property1>?</property1>
<property2>?</property2>
</Data>
</InputObject>
</soapenv:Body>
</soapenv:Envelope>
Note that both are equivalent an totally valid, so there is no need to remove the namespace prefix from the first one...
Furthermore as I said your "desired output" which you shows in your question sure not accomplish your schema definition an therefore is not valid:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://somenamespace.com">
<soapenv:Header/>
<soapenv:Body>
<ns:InputObject>
<Data>
<property1>?</property1>
<property2>?</property2>
</Data>
</ns:InputObject>
</soapenv:Body>
</soapenv:Envelope>
Hope this helps,
Upvotes: 1