SAP Consuming a .NET Webservice containing an “AnyType”
We had a few problems with SAP consuming a .NET webservice. The problem was that the post contained an array of “Attribute” objects. This Attribute object consists of 2 fields
- Name field: a string
- Value field: could be anything (an “Object” type in .NET)
The WSDL of this Attribute object looks like this
<s:complexType name="Attribute">
<s:sequence>
<s:element minOccurs=”0″ maxOccurs=”1″ name=”Name” type=”s:string”/>
<s:element minOccurs=”0″ maxOccurs=”1″ name=”Value”/>
</s:sequence>
</s:complexType>
There were 2 problems:
The SAP proxy
The SAP proxy that is generated cannot handle this untyped element. Someone had to manually adjust the SAP proxy code so that they could define the <Value> node in XML markup in the SOAP message manually. Unfortunately I’m not a SAP expert so I can’t tell you exactly how to modify the proxy.
The Value node
The second problem is the value node itself. The real problem is that SAP does strange things with the XML namespaces when sending out the SOAP message. It does not define the namespace of the webservice at some top level but redefines is at almost every node making it a) much more complicated than it really is and b) create a lot more network traffic because of all the unnecessary bytes being sent over the network.
An example:
<n0:Attribute xmlns:n0="http://mynamespace">
<n0:Name>some string array</n0:Name>
<!-- The Value node is manually generated in the SAP proxy -->
<n0:Value asx:root="Value" asx:nsd="xsd wsd"
type="ArrayOfString"
xmlns:asx="http://www.sap.com/abapxml">
<string>first string</string>
</n0:Value>
</n0:Attribute>
The value node is a string array, defined as the ArrayOfString complex type in de WSDL of the webservice. (Note the n0 namespace that is added on every Attribute node and the additional SAP namespace). The above didn’t work because the .NET webservice incorrectly deserialized the Value node
- type is an attribute in the http://www.w3.org/2001/XMLSchema-instance namespace. This namespace is not defined at any top level in the generated SOAP message and is redefined every time it’s needed
- ArrayOfString is a complex type in the namespace of our webservice http://mynamespace
Eventually the following did work
<n0:Attribute xmlns:n0="http://mynamespace">
<n0:Name>some string array</n0:Name>
<!-- The Value node is manually generated in the SAP proxy -->
<n0:Value xmlns="http://mynamespace" asx:root="Value" asx:nsd="xsd wsd"
xsi:type="ArrayOfString"
xmlns:asx="http://www.sap.com/abapxml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<string>first string</string>
</n0:Value>
</n0:Attribute>
This was our solution. If someone knows a better one, please let me know!
Advertisement