0

I have generated a c# client in Visual Studio from a WSDL via the "Add Service Reference" (wsdl simplified and included below). When I use this client to generate a request to the service, it creates child elements with an empty xmlns attribute. Here's an example request:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
        <Action s:mustUnderstand="1" 
            xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://sap.com/xi/WebService/soap1.1</Action>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <MySearchInput xmlns="http://www.example.com/mySearch">

            <SearchDetails xmlns="">

                <CompanyName>asda</CompanyName>
            </SearchDetails>
        </MySearchInput>
    </s:Body>
</s:Envelope>

For this to be a valid request for the service, the SearchDetails element should not have this empty xmls attribute, it should be inheriting the default namespace as defined on it's parent MySearchInput element.

Is there a change I can make to the wsdl so that the desired request XML will be generated by the client?

I've got a workaround that involves changing the codegen files created by Visual Studio, but I suspect there should be a more elegant solution involving changing the wsdl itself?

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="MySearch_Out" targetNamespace="urn:example.mysearch" 
    xmlns:p2="http://www.example.com/mySearch" 
    xmlns:p1="urn:example.mysearch" 
    xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" 
    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <wsdl:documentation/>
    <wsp:UsingPolicy wsdl:required="true"/>
    <wsp:Policy wsu:Id="OP_MySearch_Out"/>
    <wsdl:types>
        <xsd:schema targetNamespace="http://www.example.com/mySearch" 
            xmlns="http://www.example.com/mySearch" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:element name="MySearchInput" type="MySearchInput_TYPE"/>
            <xsd:element name="MySearchOutput" type="MySearchOutput_TYPE"/>

            <xsd:complexType name="MySearchOutput_TYPE">
                <xsd:all>

                    <xsd:element name="SearchSummary" type="MySearchOutput_SearchSummary_TYPE" minOccurs="0"/>
                </xsd:all>
            </xsd:complexType>

            <xsd:complexType name="MySearchInput_TYPE">
                <xsd:all>
                    <xsd:element name="SearchDetails" type="MySearchInput_SearchDetails_TYPE" minOccurs="0"/>
                </xsd:all>
            </xsd:complexType>

            <xsd:complexType name="MySearchInput_SearchDetails_TYPE">
                <xsd:all>
                    <xsd:element name="CompanyRef" minOccurs="0">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:string">
                                <xsd:maxLength value="8"/>
                                <xsd:pattern value="[0-9A-Z]+"/>
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:element>
                    <xsd:element name="CompanyName" minOccurs="0">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:string">
                                <xsd:maxLength value="100"/>
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:element>
                </xsd:all>
            </xsd:complexType>

            <xsd:complexType name="MySearchOutput_SearchSummary_TYPE">
                <xsd:all>
                    <xsd:element name="NumberMatches" minOccurs="0">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:integer">
                                <xsd:maxInclusive value="999"/>
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:element>
                    <xsd:element name="CompanyRef" minOccurs="0">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:string">
                                <xsd:maxLength value="20"/>
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:element>
                    <xsd:element name="CompanyName" minOccurs="0">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:string">
                                <xsd:maxLength value="100"/>
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:element>
                </xsd:all>
            </xsd:complexType>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="p2.MySearchInput">
        <wsdl:documentation/>
        <wsdl:part name="MySearchInput" element="p2:MySearchInput"/>
    </wsdl:message>
    <wsdl:message name="p2.MySearchOutput">
        <wsdl:documentation/>
        <wsdl:part name="MySearchOutput" element="p2:MySearchOutput"/>
    </wsdl:message>
    <wsdl:portType name="MySearch_Out">
        <wsdl:documentation/>
        <wsdl:operation name="MySearch_Out">
            <wsdl:documentation/>
            <wsp:Policy>
                <wsp:PolicyReference URI="#OP_MySearch_Out"/>
            </wsp:Policy>
            <wsdl:input message="p1:p2.MySearchInput"/>
            <wsdl:output message="p1:p2.MySearchOutput"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="MySearch_OutBinding" type="p1:MySearch_Out">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" 
            xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
        <wsdl:operation name="MySearch_Out">
            <soap:operation soapAction="http://sap.com/xi/WebService/soap1.1" 
                xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
            <wsdl:input>
                <soap:body use="literal" 
                    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" 
                    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="MySearch_OutService">
        <wsdl:port name="HTTP_Port" binding="p1:MySearch_OutBinding">
            <soap:address location="http://www.example.com/MySearch" 
                xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
        </wsdl:port>
        <wsdl:port name="HTTPS_Port" binding="p1:MySearch_OutBinding">
            <soap:address location="http://www.example.com/MySearch" 
                xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>
TheLogicMan
  • 371
  • 4
  • 12

1 Answers1

0

I found an answer in another StackOverflow question. I think the specifics of this question probably warrant it being a distinct question despite having the same solution.

Why is Oxygen generating child elements with empty xmlns attributes?

The solution is to add elementFormDefault="qualified" to the schema element in the WSDL.

<xsd:schema targetNamespace="http://www.example.com/mySearch" 
            xmlns="http://www.example.com/mySearch" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified">
TheLogicMan
  • 371
  • 4
  • 12