Consuming SOAP with service with name space
I´m consuming a SOAP web service, that it has namespace, some similar to:
<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions targetNamespace="http://www.company.com/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:company="http://www.company.com/"
xmlns:apachesoap="http://xml.apache.org/xm开发者_JAVA百科l-soap" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:types>
<xsd:schema elementFormDefault="qualified" targetNamespace="http://www.company.com/" version="0.1"
xmlns:cmp="http://www.company.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Number" type="cmp:NumberType" />
My problem is when .net serialize the object it does not include prefix cmp in xml. It renders <Number
.... instead of <cmp:Number
...
What can i solve it?
What happens when you send that request? Presumably it succeeds, because the cmp:NumberType
part of
<xsd:element name="Number" type="cmp:NumberType" />
refers not to the name of the element but to the name of the type in the above-referenced WSDL. It is a complex type, otherwise it would be something like xsd:int
. So, as I say, your code should still work, especially if you imported that WSDL as a WebReference into your Visual Studio project.
I've recently heard of programs that distinguish between
<Number xmlns="http://www.company.com/" />
and
<tns:Number xmlns:tns="http://www.company.com/" />
These two examples are identical in terms of the XML standards, but there are programs that don't follow the standards, and instead create their own standards.
Can you post the XML that causes the problem? Also, post the complete error message that is received.
The prefix used on an element is only valid within the scope of the prefix declaration. In other words, this 'cmp' prefix is only valid for this serialized XML.
The prefix is nothing else than an abbriviation of the namespace it stands for. In this case, "cmp" stands for {http://www.company.com/}.
When you load this XML into a DOM document the 'real declaration' for a node inside this DOM is now "{http://www.company.com/}:Number".
This is even a very short namespace, just imagine the average namespace and its size and i think we can agree why using abbreviations (called a prefix in XML) is a good idea when serializing any XML document.
But however you serialize it, it doesn't change the data its representing. So
<bla xmlns="http://www.company.com/" />
is syntaxtically different but value-wise the same as
<cmp:bla xmlns:cmp="http://www.company.com/" /> <{http://www.company.com/}:bla />
After reading this, is it actually a requirement to provide the serialized XML in a format that uses "cmp" as the prefix? (since its a soap header, i think this requirement isn't there) , or can we use ANY xml serialization style as long as we don't change the data its representing? (this is what W3C XML 1.0+Namespaces compliant parsers care about)
If its not a requrement, lets not make it one :)
If it is a requirement;
You can associate a XmlNamespaceManager with an XmlSerializer. This allows you to set up prefix-to-namespaceuri associations that will then be used during serialization of an object.
Hope this helps,
精彩评论