views:

85

answers:

3

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/xml-soap" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"&gt;
  <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"&gt;

    <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?

A: 

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.

benjy
The problem is web server use java, and it return input error.
fravelgue
A: 

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.

John Saunders
Sry, i can post details of this api. But java web server return input error. Could i change xml posted in soap request?
fravelgue
@fravelgue: can yo at least post the full error message?
John Saunders
A: 

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,

Marvin Smit
I just read that you stated it was a java service and it did throw an error when you tried to fire of your request. Before going down the XmlSerializer path, have you checked what goes over the wire? Is your soap header there? is it in the correct namespace (regardless of prefix, check the namespace-uri associated with the xmlns=´xxx´ or bla:soapheader xmlns:bla=´xxx´).Did you check with the vendors of the web service if this is a ´known problem´?
Marvin Smit