Soap клиент выбрасывает неожиданное исключение элемента - PullRequest
0 голосов
/ 21 февраля 2020

У меня есть сторонний сервис SOAP. Когда я вызываю конечную точку сервиса, используя POSTMAN, он отправляет данные обратно

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

POSTMAN Body

<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>

Любое предложение, что я делаю неправильно, или лучший способ позвонить в службу.

1 Ответ

1 голос
/ 21 февраля 2020

Сообщение об ошибке гласит: "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);
...