SOAP XML请求返回“请求格式不正确”错误

时间:2019-10-17 15:48:25

标签: java python xml soap soap-client

我正在将Python代码转换为Java。该代码是与SOAP服务器端点通信的SOAP 1.5客户端代码。

没有意义的是Python代码发送XML请求并从服务器获取可接受的响应。但是,对于Java代码,响应是一个错误,指出“请求的格式不正确”。

下面,我显示XML请求,一个以Python发送,另一个以Java发送。 Java发送的Java代码如何返回错误,但是Python正常/可以接受。它们都是有效的请求。也许我缺少明显的东西。

Python请求:

<SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
    xmlns:wsa="http://www.w3.org/2005/08/addressing"
    xmlns:cs="urn://Ocpp/Cp/2012/06/">
    <SOAP-ENV:Header>
        <cs:chargeBoxIdentity>Test</cs:chargeBoxIdentity>
        <wsa:MessageID>Fake OCPP571322528896</wsa:MessageID>
        <wsa:Action>/ChangeConfiguration</wsa:Action>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <cs:changeConfigurationRequest>
            <cs:key>LaMa_ConnectionRate</cs:key>
            <cs:value>5120</cs:value>
        </cs:changeConfigurationRequest>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Java请求:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:cs="urn://Ocpp/Cp/2012/06/"
    xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <SOAP-ENV:Header>
        <cs:chargeBoxIdentity>Test</cs:chargeBoxIdentity>
        <wsa:Action>/ChangeConfiguration</wsa:Action>
        <wsa:MessageID>Fake OCPP571322528896</wsa:MessageID>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <cs:changeConfigurationRequest>
            <cs:key>LaMa_ConnectionRate</cs:key>
            <cs:value>5120</cs:value>
        </cs:changeConfigurationRequest>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

对Java的故障响应:

<?xml version="1.0" encoding="UTF-8"?><env:Envelope 
xmlns:env="http://www.w3.org/2003/05/soap-envelope">
  <env:Header/>
  <env:Body>
    <env:Fault>
      <env:Code>
        <env:Value>env:Sender</env:Value>
      </env:Code>
      <env:Reason>
        <env:Text xml:lang="en-US">XML Request is not well formed!</env:Text>
      </env:Reason>
    </env:Fault>
  </env:Body>
</env:Envelope>

更新:

我的Java代码应该为“ SOAP-ENV”发送“ http://www.w3.org/2003/05/soap-envelope”,如下面的代码所示。但是,它将以某种方式发送“ http://schemas.xmlsoap.org/soap/envelope/”。我不明白为什么。

// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("SOAP-ENV", "http://www.w3.org/2003/05/soap-envelope");

0 个答案:

没有答案