2016-03-23 9 views
1

OCPP(Open Charge Point Protocol)を使用するシンプルなPHPクライアントで作業しています。私はクライアントを作成しました。これは私のコードからのリクエストXMLです。必要なSOAPリクエスト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出力に私のコードはenv:Envelopeを持っており、出力はns0:Envelopeを持っており、自分のコード内の余分な属性は、SOAPボディであり

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

通告を取得することとしています。私は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)); 

答えて

0

は接頭辞がEnvelope要素にxmlns宣言と一致あなたは問題ないはずですので、それは有効なXMLので、有効なSOAP提供しました。しかし、XMLでは大文字と小文字が区別されており、あなたが期待している出力のIdTag要素ではなく、Body要素内にコードがあり、要素がidTagであることがわかりました。

0

OCPPの仕様によれば、現在の出力は正しいものに近いものの、まだ多くの問題があります。

  • あなたがOCPP 1.6用ですが、あなたのコードでは、あなたがURNのため.../2012/06/を必要OCPP 1.5のWSDLを使用している.../2015/10/で終わるを使用しているフルOCPP URN。
  • OCPP仕様に従って、キャメルケースidTagAuthorizeメッセージの正しいフィールド名です。
  • SOAP本体にルートタグ<authorizeRequest />が必要です。あなたはWSA SOAPヘッダ内のフィールド(MessageIdFromToReplyToRelatesToActionに対処するための名前空間xmlns:wsa="http://www.w3.org/2005/08/addressing"を(対処する)。
  • chargeBoxIdentityがOCPP URN名前空間に属している必要があります。
  • MessageIdMessageID、それでなければなりません
  • mustUnderstand属性を持つべきではありません。
  • ActionToReplyTochargeBoxIdentitymustUnderstand="true"属性を持つ必要があります。0番目ersはしないでください。 OCPP 1.6 ReplyToのよう
  • が必要とされ、常に http://www.w3.org/2005/08/addressing/anonymous
  • RelatesToのみ応答のために必要とされる値を持つ必要があります。これはリクエストです。

期待される出力の最終版は、以下のようにする必要があります:

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

注:私は少し意味のある名前空間接頭辞を設定して、あなたが好きなものを設定することができます。

関連する問題