调用PI服务时,在解析SOAP头时出错。

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

我必须用SOAP调用一个Webservice。我在Java中做了一个客户端,产生了如下的SOAPMessage。

<?xml version="1.0" encoding="utf-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:abc="http://company.com/SAMPLE/ABC">
    <SOAP-ENV:Header />
    <SOAP-ENV:Body>
        <abc:genXX>
            <ServiceRequestID>111</ServiceRequestID>
            <Code>328630962</Code>
        </abc:genXX>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

该调用产生了 解析SOAP时出错 当我在我的应用程序里面调用它的时候,web服务的响应很好。

<SOAP:Header>
</SOAP:Header>
<SOAP:Body>
    <SOAP:Fault xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
        <faultcode>SOAP:Client</faultcode>
        <faultstring>Error during parsing of SOAP header</faultstring>
        <faultactor>http://sap.com/xi/XI/Message/30</faultactor>
        <detail>
            <SAP:Error SOAP:mustUnderstand="1"
                xmlns:SAP="http://sap.com/xi/XI/Message/30">
                <SAP:Category>XIProtocol</SAP:Category>
                <SAP:Code area="PARSER" />
                <SAP:P1 />
                <SAP:P2 />
                <SAP:P3 />
                <SAP:P4 />
                <SAP:AdditionalText />
                <SAP:Stack>System error in parser
                </SAP:Stack>
            </SAP:Error>
        </detail>
    </SOAP:Fault>
</SOAP:Body>
</SOAP:Envelope>

但当我在同一台电脑上用SOAP用户界面调用它时 网络服务的响应很好。我的应用程序中的客户端是这样做的。

public void callWebservice(String serviceRequestID, String code) {
    try {
            // Create SOAP Connection
            SOAPConnectionFactory soapConnectionFactory =
               SOAPConnectionFactory.newInstance();
            SOAPConnection soapConnection = soapConnectionFactory.createConnection();

            // Send SOAP Message to SOAP Server
            URLEndpoint url = new URLEndpoint ("http://company.com:50000/");
            SOAPMessage soapResponse =  soapConnection.call(
               createSOAPRequest(serviceRequestID, code), url);


            {...}

            soapConnection.close();
        } catch (Exception e) {
           //
        }

private SOAPMessage createSOAPRequest(String serviceRequestID, 
    String code) throws SOAPException{
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage soapMessage = messageFactory.createMessage();

        SOAPPart soapPart = soapMessage.getSOAPPart();

        String serverURI = "http://company.com/SAMPLE/ABC";

        // SOAP Envelope
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.addNamespaceDeclaration("abc", serverURI);

        // SOAP Body
        SOAPBody soapBody = envelope.getBody();
        SOAPElement soapBodyElem = soapBody.addChildElement("genXXX", "abc");
        SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("ServiceRequestID");
        SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("Code");

        soapBodyElem1.addTextNode(serviceRequestID);
        soapBodyElem2.addTextNode(code);

        MimeHeaders headers = soapMessage.getMimeHeaders();
        headers.addHeader("SOAPAction", serverURI );

        String loginPassword = "USER:PASSWORD";
        headers.addHeader("Authorization", "Basic " + new  
          String(Base64.encodeBase64(loginPassword.getBytes())));

        soapMessage.saveChanges();

        return soapMessage;
    }

  }

我已经检查了头和认证,是正确的。如果我改变了用户或密码,Webservice的响应是401 Unauthorized,所以我认为头是按照预期发送的。

你有什么线索可以告诉我是什么原因导致我的应用程序出现错误吗?

java soap sap sap-xi sap-pi
1个回答
0
投票

你正在调用SAP PI(SAP流程集成)中的一个Web服务。我是一名PI开发人员,可以在SOAP上使用SAP专有的协议,称为XI protocal,在SAP-SAP场景中很有用。如果这个服务应该被一个非SAP系统访问,它可能应该被改变为常规的SOAP 1.1协议。请与PI团队讨论。

© www.soinside.com 2019 - 2024. All rights reserved.