Skip to content

Force xsi:type to appear on request element #1474

@ale-rinaldi

Description

@ale-rinaldi

Hello,

I'm integrating with a service whose WSDL is unfortunately private, but it's similar to this toy version (input parameters are intentionally over-complicated here to match the real scenario):

  • service.wsdl:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
	xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:mysvc="http://www.example.org/schemas/mysvc"
	xmlns:mycalc="http://www.example.org/schemas/mycalc"
	targetNamespace="http://www.example.org/schemas/mysvc">


	<wsdl:types>
		<xs:schema xmlns="http://www.w3.org/2001/XMLSchema">
			<xs:import namespace="http://www.example.org/schemas/mycalc"
				schemaLocation="schema.xsd"/>
		</xs:schema>
	</wsdl:types>

	
	<!-- *** Messages *** -->
	
	<wsdl:message name="sumRequest">
		<wsdl:part name="SumParameters" type="mycalc:sumParametersType"/>
	</wsdl:message>

	<wsdl:message name="sumResponse">
		<wsdl:part name="SumResult" type="xs:int"/>
	</wsdl:message>

	<!-- *** PortTypes *** -->

	<wsdl:portType name="Calculator">
		<wsdl:operation name="sum">
			<wsdl:input message="mysvc:sumRequest"/>
			<wsdl:output message="mysvc:sumResponse"/>
		</wsdl:operation>
	</wsdl:portType>


	<!-- *** Bindings *** -->

	<wsdl:binding name="CalculatorBinding" type="mysvc:Calculator">

		<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

		<wsdl:operation name="sum">
			<soap:operation soapAction="sum"/>
			<wsdl:input>
				<soap:body
					namespace="http://www.example.org/schemas/mycalc"
					parts="SumParameters" use="literal"/>
			</wsdl:input>
			<wsdl:output>
				<soap:body
					namespace="http://www.example.org/schemas/mycalc"
					parts="SumResult" use="literal"/>
			</wsdl:output>
		</wsdl:operation>
	</wsdl:binding>


	<!-- *** Services *** -->

	<wsdl:service name="CalculatorService">
		<wsdl:port name="CalculatorPort" binding="mysvc:CalculatorBinding">
			<soap:address location="http://localhost:8080/myservice"/>
		</wsdl:port>
	</wsdl:service>

</wsdl:definitions>
  • schema.xsd
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:mycalc="http://www.example.org/schemas/mycalc"
    elementFormDefault="qualified"
    targetNamespace="http://www.example.org/schemas/mycalc">
    
    <complexType name="sumParametersType">
        <complexContent>
            <restriction base="mycalc:sumParametersType">
                <sequence>
                    <element name="NumbersToAdd" type="mycalc:numbersToAddType" minOccurs="1" maxOccurs="1"/>
                </sequence>
            </restriction>
        </complexContent>
    </complexType>
    <complexType name="numbersToAddType">
        <complexContent>
            <restriction base="mycalc:numbersToAddType">
                <sequence>
                    <element name="NumA" type="int" minOccurs="1" maxOccurs="1"/>
                    <element name="NumB" type="int" minOccurs="1" maxOccurs="1"/>
                </sequence>
            </restriction>
        </complexContent>
    </complexType>
</schema>
  • Code I'm running:
from zeep import Client
from lxml import etree

client = Client("wsdl/service.wsdl")

client.set_ns_prefix("mycalc", "http://www.example.org/schemas/mycalc")

mycalc = client.type_factory("mycalc")

request = mycalc.sumParametersType(
    NumbersToAdd=mycalc.numbersToAddType(
        NumA=10,
        NumB=20,
    )
)

message = client.create_message(client.service, "sum", request)
print(etree.tostring(message, pretty_print=True).decode())

This would generate the following request:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mycalc="http://www.example.org/schemas/mycalc">
  <soap-env:Body>
    <mycalc:sum>
      <SumParameters>
        <mycalc:NumbersToAdd>
          <mycalc:NumA>10</mycalc:NumA>
          <mycalc:NumB>20</mycalc:NumB>
        </mycalc:NumbersToAdd>
      </SumParameters>
    </mycalc:sum>
  </soap-env:Body>
</soap-env:Envelope>

The service will complain because SumParameters is missing the "xsi:type" attribute. In fact, if I change the request like this:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mycalc="http://www.example.org/schemas/mycalc">
  <soap-env:Body>
    <mycalc:sum>
      <SumParameters xsi:type="mycalc:sumParametersType">
        <mycalc:NumbersToAdd>
          <mycalc:NumA>10</mycalc:NumA>
          <mycalc:NumB>20</mycalc:NumB>
        </mycalc:NumbersToAdd>
      </SumParameters>
    </mycalc:sum>
  </soap-env:Body>
</soap-env:Envelope>

then it's correctly accepted.

Is there a way to force the presence of the xsi:type parameter?

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions