Soap 客户端抛出意外的元素异常

Soap client throwing Unexpected element exception

我有第 3 方 SOAP 服务。当我使用 POSTMAN 调用服务的终点时,它会发回数据

POST - https://localhost:8443/api/PatronSearch

POST男体

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sch="http://www.myservice.com/api/schema">
<soapenv:Header/>
<soapenv:Body>
<sch:PatronSearch>
<sch:Patron>
<sch:LastName>Summers</sch:LastName> 
</sch:Patron>
</sch:PatronSearch>
</soapenv:Body>
</soapenv:Envelope>

POSTMAN

中的响应
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <PatronList xmlns:ns2="http://www.myservice.com/api" xmlns="http://www.myservice.com/api/schema">
            <Patron xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="EmployeeData">
                <Id>1</Id>
                <Type>Employee</Type>
                <ReadOnly>false</ReadOnly>
                <LastName>Summers</LastName>
                <FirstName>Petron</FirstName>
                <Gender>Male</Gender>
                <PhoneNo>+14567891234</PhoneNo>
                <Language>en</Language>
                <MobilePhoneNo>+14567891235</MobilePhoneNo>
                <Email>Summers.Petron@gmail.com</Email>
                <DepartmentId>2</DepartmentId>
            </Patron>
        </PatronList>
    </soap:Body>
</soap:Envelope>

但是当我尝试使用 java 访问相同的服务时,它抛出了以下错误

org.springframework.ws.soap.client.SoapFaultClientException: Unexpected element findPatron found.   Expected {http://www.myservice.com/api/schema}PatronSearch.

这是我调用此服务的方法

public PatronList getPatronInfo(PatronSearch patronSearch) {
        template = new WebServiceTemplate(marshaller);

        JAXBElement<PatronSearch> jaxbElement = new JAXBElement<PatronSearch>(new QName("", "findPatron"),
                PatronSearch.class, patronSearch);

        PatronList patronList = (PatronList) template
                .marshalSendAndReceive("https://localhost:8443/api/PatronSearch", jaxbElement);

        return patronList;
    }

这里是wsdl的截图

    <?xml version="1.0" encoding="utf-8"?>
<!--Created with Liquid XML Studio Developer Edition 9.1.11.3570 (http://www.liquid-technologies.com)-->
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://example.com/" xmlns:ns="http://www.myservice.com/api/schema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" name="myservice" targetNamespace="http://www.myservice.com/api" xmlns="http://schemas.xmlsoap.org/wsdl/">
    <types>
        <xs:schema xmlns:tns="http://schemas.xmlsoap.org/wsdl/">
            <xs:import schemaLocation="MyServiceWebService.xsd" namespace="www.myservice.com/api/schema" />
        </xs:schema>
    </types>
    <message name="PatronSearch">
        <part xmlns:q1="http://www.myservice.com/api/schema" name="search" element="q1:PatronSearch" />
    </message>
    <message name="PatronList">
        <part xmlns:q1="http://www.myservice.com/api/schema" name="list" element="q1:PatronList" />
    </message>
    <portType name="MyServiceWebServiceType">
    <operation name="findPatron">
            <input xmlns:q1="http://www.myservice.com/api" name="findPatron" message="q1:PatronSearch" />
            <output xmlns:q1="http://www.myservice.com/api" name="listPatron" message="q1:PatronList" />
            <fault xmlns:q1="http://www.myservice.com/api" name="fout" message="q1:Fault" />
        </operation>
        </portType>

        <binding xmlns:q1="http://www.myservice.com/api/" name="MyServiceWebServiceSoapBinding" type="q1:MyServiceWebServiceType">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
        <operation name="findPatron">
            <input name="findPatron" />
            <output name="listPatron" />
            <fault name="fout" />
        </operation>
        </binding>
    <service name="MyServiceWebService">
        <port xmlns:q1="http://www.myservice.com/api" name="MyServiceWebServicePort" binding="q1:MyServiceWebServiceSoapBinding">
            <soap:address location="https://localhost:8443/api" />
        </port>
    </service>
</definitions>

关于我做错了什么或调用服务的更好方法的任何建议。

错误消息指出:“Expected {http://www.myservice.com/api/schema}PatronSearch”。构造 QName 时提供适当的命名空间和本地名称:

JAXBElement<PatronSearch> jaxbElement = new JAXBElement<PatronSearch>(new QName("http://www.myservice.com/api/schema", "PatronSearch"), PatronSearch.class, patronSearch);