未获取所需的SOAP请求XML [英] Not getting the required SOAP request XML

查看:68
本文介绍了未获取所需的SOAP请求XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OCPP(开放收费点协议)的简单php客户端上工作.我已经创建了客户端,这是来自我的代码的请求XML.

I am working on a Simple php Client that uses OCPP (Open Charge Point Protocol). I have created the client and This is the request XML that goes from my code.

<?xml version="1.0" encoding="UTF-8"?>
  <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urn://Ocpp/Cs/2015/10/">
      <env:Header>
          <ns1:chargeBoxIdentity env:mustUnderstand="true">XXX01</ns1:chargeBoxIdentity>
          <ns1:Action env:mustUnderstand="true">/Authorize</ns1:Action>
          <ns1:MessageId env:mustUnderstand="true">123</ns1:MessageId>
          <ns1:RelatesTo>relatesTo</ns1:RelatesTo>
          <ns1:From/>
          <ns1:ReplyTo/>
          <ns1:To/>
      </env:Header>
      <env:Body>
          <ns1:authorizeRequest>
          <ns1:idTag>1234567</ns1:idTag>
          </ns1:authorizeRequest>
      </env:Body>
  </env:Envelope>

但是我想得到这个XML输出

But I am suppose to get this XML output

<?xml version='1.0' encoding='utf8'?> 
<ns0:Envelope xmlns:ns0="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urn://Ocpp/Cs/2015/10/">
    <ns0:Header>
        <ns1:chargeBoxIdentity mustUnderstand="true">XXX01 </ns1:chargeBoxIdentity>
        <ns1:Action mustUnderstand="true">/Authorize</ns1:Action>
        <ns1:MessageId mustUnderstand="true">123</ns1:MessageId>
        <ns1:RelatesTo>relatesTo</ns1:RelatesTo>
        <ns1:From />
        <ns1:ReplyTo />
        <ns1:To />
    </ns0:Header>
    <ns0:Body>
        <ns1:IdTag>1234567</ns1:IdTag>
    </ns0:Body>
</ns0:Envelope>

请注意,我的代码具有env:Envelope,输出具有ns0:Envelope,并且在我的代码中,Soap Body中具有extra属性.我对php SOAP的了解非常有限.相关代码如下.

Notice that my code has env:Envelope and output has ns0:Envelope and in my code extra attribute is there in the Soap Body. I have very limited knowledge in php SOAP. The relevant code is below.

ini_set('soap.wsdl_cache_enabled',0);

$wsdl_centralsystem = "OCPP_centralsystemservice_1.5_final.wsdl";
$params =  "0.1.1.255.0.0.1.0.";

$vLocation = "linktoserver/server.php";

$client = new SoapClient($wsdl_centralsystem, array(

    "soap_version" => SOAP_1_2,
    "location" => $vLocation,
    "trace"=>1, "exceptions"=>0,

));

$chargeboxid = "XXX01";
$action = "/Authorize";
$msgid = "123";
$relatesto = "relatesTo";


//Create Soap Headers
$headerCchargeBoxIdentity = new SoapHeader("urn://Ocpp/Cs/2015/10/", 'chargeBoxIdentity', $chargeboxid, true);
$headerAction = new SoapHeader("urn://Ocpp/Cs/2015/10/", 'Action', $action, true);
$headerMessageId = new SoapHeader("urn://Ocpp/Cs/2015/10/", 'MessageId', $msgid, true);
$headerRelatesTo = new SoapHeader("urn://Ocpp/Cs/2015/10/", 'RelatesTo', $relatesto, false);
$headerFrom = new SoapHeader("urn://Ocpp/Cs/2015/10/", 'From', NULL, false);
$headerReplyTo= new SoapHeader("urn://Ocpp/Cs/2015/10/", 'ReplyTo', NULL, false);
$headerTo = new SoapHeader("urn://Ocpp/Cs/2015/10/", 'To', NULL, false);

//set the Headers of Soap Client.
$client->__setSoapHeaders(array($headerCchargeBoxIdentity,$headerAction,$headerMessageId,$headerRelatesTo,$headerFrom,$headerReplyTo,$headerTo));


$output = $client-> __soapCall('Authorize',array($params));

推荐答案

根据OCPP规范,您当前的输出接近正确的输出,但是仍然存在许多问题.

According to OCPP specs, your current output is closer to what's correct but still has many problems.

  • 您正在使用的完整OCPP URN以.../2015/10/结尾,该字符用于OCPP 1.6,但是在您的代码中,您使用的是WSDL for OCPP 1.5,它需要.../2012/06/用于URN.
  • 根据OCPP规范,驼峰式idTagAuthorize消息的正确字段名称.
  • 您需要在SOAP正文中使用根标记<authorizeRequest />.
  • 您需要WSA(寻址)命名空间xmlns:wsa="http://www.w3.org/2005/08/addressing"来寻址SOAP标头中的字段(MessageIdFromToReplyToRelatesToAction).
  • chargeBoxIdentity属于OCPP URN命名空间.
  • MessageId应该为MessageID,并且不应具有mustUnderstand属性.
  • ActionToReplyTochargeBoxIdentity应该具有mustUnderstand="true"属性.其他人不应该.
  • 从OCPP 1.6开始,ReplyTo是必需的,并且应始终具有值http://www.w3.org/2005/08/addressing/anonymous
  • RelatesTo仅对于响应是必需的.这是一个请求.
  • The full OCPP URN you're using ends with .../2015/10/ which is for OCPP 1.6 but in your code, you're using WSDL for OCPP 1.5 which requires .../2012/06/ for URN.
  • Per OCPP spec, camel-case idTag is correct field name for Authorize message.
  • You need the root tag <authorizeRequest /> in the SOAP body.
  • You need WSA (addressing) namespace xmlns:wsa="http://www.w3.org/2005/08/addressing" for addressing fields (MessageId, From, To, ReplyTo, RelatesTo and Action in the SOAP header.
  • chargeBoxIdentity belongs to OCPP URN namespace.
  • MessageId should be MessageID and it should not have mustUnderstand attribute.
  • Action, To, ReplyTo and chargeBoxIdentity should have mustUnderstand="true" attribute. Others should not.
  • As of OCPP 1.6 ReplyTo is required and should always have the value http://www.w3.org/2005/08/addressing/anonymous
  • RelatesTo is required for responses only. This is a request.

预期输出的最终版本应如下:

Final version of the expected output should be like below:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
        xmlns:cs="urn://Ocpp/Cs/2012/06/"
        xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <soap:Header>
        <cs:chargeBoxIdentity soap:mustUnderstand="true">XXX01</cs:chargeBoxIdentity>
        <wsa:Action soap:mustUnderstand="true">/Authorize</wsa:Action>
        <wsa:MessageID>123</wsa:MessageID>
        <wsa:From><wsa:Address>http://from-endpoint</wsa:Address></wsa:From>
        <wsa:ReplyTo soap:mustUnderstand="true"><wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address></wsa:ReplyTo>
        <wsa:To soap:mustUnderstand="true"><wsa:Address>http://to-endpoint</wsa:Address></wsa:To>
    </soap:Header>
    <soap:Body>
        <cs:authorizeRequest>
            <cs:idTag>1234567</cs:idTag>
        </cs:authorizeRequest>
    </soap:Body>
</soap:Envelope>

注意:我已经设置了一些有意义的名称空间前缀,您可以设置任何您喜欢的内容.

这篇关于未获取所需的SOAP请求XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆