Soap client抛出意外元素异常

问题描述 投票:0回答:1

我有一个第三方SOAP服务。当我使用POSTMAN调用服务的终点时,它将数据发送回去

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

邮递员正文

<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>[email protected]</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>

任何建议,我做错了什么或致电服务的更好方法。

java web-services wsdl soap-client
1个回答
1
投票

错误消息状态:“ 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);
© www.soinside.com 2019 - 2024. All rights reserved.