Soap Web服务结构

时间:2014-11-20 11:02:31

标签: php web-services soap wsdl

我正在开发一个带有.net网络服务的集成项目,我正在使用php soap访问它。

它始终是一个挑战,但我设法找到了正确的方法来调用除了这一种方法之外的东西,这是为了添加产品订单行,产品有选项。

以下是针对产品记录的产品问答回复(低于1个问题,实际上有3个针对此产品);

[GetOptionQuestionsResult] => stdClass Object
    (
        [OptionQuestion] => Array
            (
                [0] => stdClass Object
                    (
                        [OptionQuestionID] => 7373
                        [Descriptor] => Scatter Fabric Front.
                        [OptionType] => Choice
                        [OptionQuantityType] => OneOnly
                        [OptionPriceType] => NotSet
                        [OptionChoices] => stdClass Object
                            (
                                [OptionChoice] => Array
                                    (
                                        [0] => stdClass Object
                                            (
                                                [OptionID] => 17053
                                                [Value] => Pastiche Chocolate
                                                [SellingPrice] => 0
                                                [HasOptions] => 
                                            )[1] => stdClass Object
                                            (
                                                [OptionID] => 17054
                                                [Value] => Pastiche Sage
                                                [SellingPrice] => 0
                                                [HasOptions] => 
                                            )

                                        [2] => stdClass Object
                                            (
                                                [OptionID] => 17055
                                                [Value] => Pastiche Spruce
                                                [SellingPrice] => 0
                                                [HasOptions] => 
                                            )

                                        [3] => stdClass Object
                                            (
                                                [OptionID] => 17056
                                                [Value] => Stilnovo Paisley
                                                [SellingPrice] => 0
                                                [HasOptions] => 
                                            )

                                    )

                            )

                    )

以下是使用wsdl中的选项添加产品的方法,该选项名为AddOrderLineForBaseProduct。加上用于添加实际答案的附加元素(OptionAnswerForChoice / OptionAnswerForFreetext);

<s:element name="AddOrderLineForBaseProduct">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="1" maxOccurs="1" name="BaseProductID" type="s:int" />
        <s:element minOccurs="0" maxOccurs="1" name="optionAnswers" type="tns:ArrayOfOptionAnswer" />
        <s:element minOccurs="1" maxOccurs="1" name="Quantity" type="s:int" />
        <s:element minOccurs="1" maxOccurs="1" name="BaseSellingPrice" type="s:decimal" />
        <s:element minOccurs="1" maxOccurs="1" name="VATID" type="s:int" />
        <s:element minOccurs="1" maxOccurs="1" name="TakeFromStock" type="s:boolean" />
        <s:element minOccurs="1" maxOccurs="1" name="LeadTime" type="s:int" />
        <s:element minOccurs="1" maxOccurs="1" name="PromotionID" type="s:int" />
      </s:sequence>
    </s:complexType>
  </s:element>
  <s:complexType name="ArrayOfOptionAnswer">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="unbounded" name="OptionAnswer" nillable="true" type="tns:OptionAnswer" />
    </s:sequence>
  </s:complexType>
  <s:complexType name="OptionAnswer">
    <s:sequence>
      <s:element minOccurs="1" maxOccurs="1" name="_optionType" type="tns:OptionQuestionType" />
      <s:element minOccurs="1" maxOccurs="1" name="_optionQuantityType" type="tns:OptionQuestionQuantityType" />
      <s:element minOccurs="1" maxOccurs="1" name="_optionPriceType" type="tns:OptionQuestionPriceType" />
      <s:element minOccurs="1" maxOccurs="1" name="OptionQuestionID" type="s:int" />
      <s:element minOccurs="1" maxOccurs="1" name="Quantity" type="s:decimal" />
      <s:element minOccurs="1" maxOccurs="1" name="SellingPrice" type="s:decimal" />
    </s:sequence>
  </s:complexType>
  <s:complexType name="OptionAnswerForFreeText">
    <s:complexContent mixed="false">
      <s:extension base="tns:OptionAnswer">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="FreeText" type="s:string" />
        </s:sequence>
      </s:extension>
    </s:complexContent>
  </s:complexType>
  <s:complexType name="OptionAnswerForChoice">
    <s:complexContent mixed="false">
      <s:extension base="tns:OptionAnswer">
        <s:sequence>
          <s:element minOccurs="1" maxOccurs="1" name="OptionID" type="s:int" />
          <s:element minOccurs="0" maxOccurs="1" name="OptionAnswers" type="tns:ArrayOfOptionAnswer" />
        </s:sequence>
      </s:extension>
    </s:complexContent>
  </s:complexType>

这是我在php中构建的用于添加选项的数组,我只是分享第一个&#39; OptionAnswer&#39;;

$optionsAnswers['OptionAnswer'][] = array(


    'OptionQuestionID' => 7373,
    '_optionType' => 'Choice',
    '_optionQuantityType' => 'OneOnly',
    '_optionPriceType' => 'NotSet',
    'Quantity' => 1,
    'SellingPrice' => '0',

    // TRYING TO ANSWER THE QUESTION HERE
    //'OptionID' => 17053,
    //'OptionAnswerForChoice' => array('OptionID' => 17053),
    //'OptionAnswer' => array('OptionAnswerForChoice' => array('OptionID' => 17053)),
    //'OptionChoices' => (object)array(
    //  'OptionID' => 17053,
    //  'SellingPrice' => '0'
    //),
    //'OptionChoiceID' => 17053,

    );

正如您所看到的,我尝试设置问题的实际答案ID时尝试了各种角度,但它们都被忽略了。

当我运行这个过程时;

//build order line array
$orderLine = array(
'BaseProductID' => $productId,
'optionAnswers' => $optionsAnswers,
'Quantity' => 1,
'BaseSellingPrice' => $linePrice,
'SellingPrice' => $linePrice,
'VATID' => 5,
'VATAmount' => $lineVat,
'TakeFromStock' => false,
'LeadTime' => $leadTime,
'PromotionID' => $promoId

);


try {
$addOrderLine = $client->__call('AddOrderLineForBaseProduct',array('parameters' => $orderLine));
} catch (Exception $e) {
print_r($e);
}

来自网络服务的反馈是;

[detail] => stdClass Object
    (
        [NetWebServiceException] => Neither Choice nor FreeText has been specified. (at OptionAnswer position 1).
    )

)

任何人都可以看到如何将OptionID添加到OptionQuestion数组中吗?

非常感谢您的期待。

1 个答案:

答案 0 :(得分:0)

使部分wsdl更难看,但是你给出的值的类型应该对应于wsdl中指定的type属性。例如,您有'_optionType' => 'Choice',&#34; Choice&#34;的值。应该是一个复杂类型的&#34; OptionQuestionType&#34;但你只是给它一个字符串。希望有所帮助。