我正在做一个简单的php客户端,使用OCPP (开放收费点协议)。我已经创建了客户端,这是来自我的代码的请求XML。
<?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输出
<?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主体中。我在php SOAP方面的知识非常有限。相关代码如下。
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));发布于 2017-07-31 18:55:41
如果前缀与Envelope元素上的xmlns声明相匹配,那么它就是有效的XML,因此也就是有效的SOAP,所以应该没问题。但是,XML是区分大小写的,我注意到您的代码在Body元素内有和idTag元素,而不是您期望的输出中的IdTag元素。
发布于 2017-08-02 08:01:39
根据OCPP规范,您当前的输出更接近于正确的输出,但仍然存在许多问题。
.../2015/10/结尾,该URN用于OCPP1.6,但在您的代码中,您为OCPP1.5使用了WSDL,它要求URN使用.../2012/06/。idTag是Authorize消息的正确字段名称。H19您在SOAP正文中需要根标记D10。您需要WSA (寻址)命名空间D13用于寻址字段(D14、D15、D16、D17SOAP header.
chargeBoxIdentity中属于attribute.Action,namespace.MessageId的RelatesTo和Action应为MessageID,并且不应具有mustUnderstand OCPP To,ReplyTo和chargeBoxIdentity应具有mustUnderstand="true"属性。从OCPP1.6 ReplyTo开始,http://www.w3.org/2005/08/addressing/anonymousRelatesTo is required for responses。这是一个请求。预期输出的最终版本应如下所示:
<?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>注意:我已经设置了一些有意义的名称空间前缀,你可以设置任何你喜欢的东西。
https://stackoverflow.com/questions/36185128
复制相似问题