Not getting the required SOAP request XML
Asked Answered
C

2

1

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>

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>

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));
Cuneo answered 23/3, 2016 at 17:41 Comment(0)
T
1

Provided the prefixes match up with the xmlns declarations on the Envelope element, then it is valid XML and therefore valid SOAP so you should be fine. However, XML is case sensitive and I notice that your code has and idTag element in inside the Body element rather than the IdTag element in the output you're expecting.

Timberland answered 31/7, 2017 at 10:55 Comment(0)
E
1

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

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

Note: I've set a bit meaningful namespace prefixes, you can set anything you like.

Emelyemelyne answered 2/8, 2017 at 0:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.