2016-07-27 2 views
0

私はSOAPエンドポイントを持っており、リクエストを送信するためにPHPの\ SoapClientクラスを使用したいと思います。問題はたとえ "senderAddress"属性がたとえあったとしても。 "name"、 "nameDetail"、 "type"属性(それらのうちのいくつかはドキュメントによって必要とされます)の場合、生成されたXML要求にはそれらが含まれません。それが受け入れ/生成する唯一の属性は "id"属性です。SoapClientが正しいリクエストを生成しない

同様の問題は、貨物オブジェクトの他の部分にも同じ問題があります。 Pickupパートは "date"属性だけを設定でき、他のすべてはスキップ/無視されます。

私は、データオブジェクトずに、いくつかのダミーコードの下だけの単純な配列を用意しました:

<?php 
$soapClient = new \SoapClient("https://capi.dpdportal.sk/apix/shipment/?wsdl", [ 
    'trace' => 1 
]); 
$headers = array(); 
$dpdSecurity = new \stdClass(); 
$token = new \stdClass(); 
$token->ClientKey = "topsecretkey"; 
$token->Email = "topsecretmail"; 
$dpdSecurity->SecurityToken = $token; 
$headers["auth"] = new \SoapHeader('http://www.dpdportal.sk/XMLSchema/DPDSecurity/v2', 'DPDSecurity', $dpdSecurity); 
$soapClient->__setSoapHeaders($headers); 
$shipment = [ 
    "reference" => "123", 
    "delisId" => "123", 
    "addressSender" => [ 
     "type" => "b2c", // this attribute is missing in the Request 
     "id" => 41656415651, 
     "nameDetail" => "test", // this attribute is missing in the Request 
    ], 
    "addressRecipient" => "123", 
    "product" => 9, 
    "parcels" => [], 
    "pickup" => null, 
]; 
$params = [ 
    'shipment' => $shipment, 
]; 
try { 
    $response = $soapClient->CreateV1($params); 
    echo '==' . PHP_EOL; 
    var_dump($response); 
} catch (\Exception $e) { 
    echo $e->getMessage(); 
} 

生成された要求:addressSender要素はタイプSHIPMENT:addressEnvelopeであること

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.dpdportal.sk/XMLSchema/SHIPMENT/v1" xmlns:ns2="http://www.dpdportal.sk/XMLSchema/DPDSecurity/v2"> 
    <SOAP-ENV:Header> 
     <ns2:DPDSecurity> 
     <ns2:SecurityToken> 
      <ns2:ClientKey>topsecretkey</ns2:ClientKey> 
      <ns2:Email>topsecretmail</ns2:Email> 
     </ns2:SecurityToken> 
     </ns2:DPDSecurity> 
    </SOAP-ENV:Header> 
    <SOAP-ENV:Body> 
     <ns1:CreateRequest> 
     <ns1:shipment> 
      <ns1:reference>123</ns1:reference> 
      <ns1:delisId>123</ns1:delisId> 
      <ns1:product>9</ns1:product> 
      <ns1:pickup /> 
      <ns1:addressSender> 
       <ns1:id>41656415651</ns1:id> 
      </ns1:addressSender> 
      <ns1:addressRecipient /> 
      <ns1:parcels /> 
     </ns1:shipment> 
     </ns1:CreateRequest> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

答えて

0

Shipment v1 schema状態このように定義される:

<xsd:complexType name="addressEnvelope"> 
    <xsd:annotation> 
     <xsd:documentation>Address envelope</xsd:documentation> 
    </xsd:annotation> 
    <xsd:choice> 
     <xsd:sequence> 
      <xsd:element name="id" type="SHIPMENT:idType" minOccurs="0"> 
       <xsd:annotation> 
        <xsd:documentation>Address ID</xsd:documentation> 
       </xsd:annotation> 
      </xsd:element> 
     </xsd:sequence> 

     <xsd:sequence> 
      <xsd:element name="type" type="SHIPMENT:addresstypeType" minOccurs="0" /> 

      <xsd:element name="name" type="SHIPMENT:nameType" minOccurs="0"> 
       <xsd:annotation> 
        <xsd:documentation>Contact person</xsd:documentation> 
       </xsd:annotation> 
      </xsd:element> 

      <xsd:element name="nameDetail" type="SHIPMENT:nameType" minOccurs="0"> 
       <xsd:annotation> 
        <xsd:documentation>Contact person (detail)</xsd:documentation> 
       </xsd:annotation> 
      </xsd:element> 

      <xsd:element name="street" type="SHIPMENT:streetType" minOccurs="0" /> 

      <xsd:element name="streetDetail" type="SHIPMENT:streetType" minOccurs="0"> 
       <xsd:annotation> 
        <xsd:documentation>Street (detail)</xsd:documentation> 
       </xsd:annotation> 
      </xsd:element> 

      <xsd:element name="houseNumber" type="SHIPMENT:houseNumberType" minOccurs="0" /> 

      <xsd:element name="zip" type="SHIPMENT:zipType" minOccurs="0" /> 

      <xsd:element name="country" type="SHIPMENT:countryType" minOccurs="0" /> 

      <xsd:element name="city" type="SHIPMENT:cityType" minOccurs="0" /> 

      <xsd:element name="phone" type="SHIPMENT:phoneType" minOccurs="0" /> 

      <xsd:element name="email" type="SHIPMENT:emailType" minOccurs="0" /> 

      <xsd:element name="reference" type="SHIPMENT:referenceType" minOccurs="0"> 
       <xsd:annotation> 
        <xsd:documentation>Reference for address (e.g. specific code of client)</xsd:documentation> 
       </xsd:annotation> 
      </xsd:element> 

      <xsd:element name="note" type="SHIPMENT:noteType" minOccurs="0"> 
       <xsd:annotation> 
        <xsd:documentation>Free note related to address</xsd:documentation> 
       </xsd:annotation> 
      </xsd:element> 

      <xsd:element name="ico" type="SHIPMENT:icoType" minOccurs="0" /> 

      <xsd:element name="vatId" type="SHIPMENT:vatIdType" minOccurs="0" /> 

      <xsd:element name="vatId2" type="SHIPMENT:vatId2Type" minOccurs="0" /> 
     </xsd:sequence> 
    </xsd:choice> 
</xsd:complexType> 

addressEnvelopeが選択肢なので、シーケンスの1つだけを定義することができます。データにはidが含まれているため、SoapClientは最初のシーケンスを使用します。さらにテストの際

更新 は、私が最初のシーケンスが唯一の有効なものを提供する任意のデータになり、オプションid要素を持っているので、SoapClientは、第二の配列を選択することはありませんと結論付けることができます。 SoapClientに第2のシーケンスを選択させる唯一の方法は、id要素のminOccursの値を1に変更することです。 これを行うには、WSDLファイルとShipment v1スキーマの両方をダウンロードし、それらをローカルにホストし、URLを更新する必要があります。

+0

私はこの質問には言及していませんが、2番目のシーケンスからすべての属性を定義しても、結果に出現する要素 "id"だけがあります。 idを持つサービスの場合、addressSender要素は空になります。 – JCZ

+0

実際には、最初のシーケンスにはオプションのidだけが含まれているため、空になります。したがって、常に有効なので、SoapClientは常に最初のシーケンスを選択すると思います。自分でコードをテストしたところ、 'ShipmentSchema_v1.xsd'の' id'要素の 'minOccurs'を' 1'に変更するだけで動作させることができました。 'SoapClient'をインスタンス化するときは、wsdlファイルとxsdファイルの両方をローカルにホストし、ローカルwsdlファイルを指す必要があります。 – Pieter

+0

あなたの '' addressRecipient "=>" 123 "'は無効です。それを動作させるには、 '' addressRecipient "=> [" id "=> 123]に変更する必要があります。 – Pieter

関連する問題