我在尝试使用PHP执行SOAP请求时收到此错误。我不能为我的生活弄清楚为什么因为对象在数组中。我已经在SO上查看了十几个错误,无法提出解决方案。提前谢谢。
错误:
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object hasn't 'Pieces' property in /home/content/html/rr.php:43
Stack trace:
#0 /home/content/html/rr.php(63): SoapClient->__call('RateQuote', Array)
#1 /home/content/html/rr.php(63): SoapClient->RateQuote(Array)
#2 {main}
thrown in /home//html/rr.php on line 43
违规行:$return = $client->RateQuote(array('request'=>$params));
数组print_r($ params):
Array
(
[QuoteRequest] => Array
(
[Pieces] => 0
[ShipDate] => 2014-09-19
)
)
Var转储:
array(6) {
[0]=>
string(50) "RateQuoteResponse RateQuote(RateQuote $parameters)"
[1]=>
string(77) "RateQuoteByAccountResponse RateQuoteByAccount(RateQuoteByAccount $parameters)"
[2]=>
string(107) "RateQuoteByAccountByTerminalResponse RateQuoteByAccountByTerminal(RateQuoteByAccountByTerminal $parameters)"
[3]=>
string(50) "RateQuoteResponse RateQuote(RateQuote $parameters)"
[4]=>
string(77) "RateQuoteByAccountResponse RateQuoteByAccount(RateQuoteByAccount $parameters)"
[5]=>
string(107) "RateQuoteByAccountByTerminalResponse RateQuoteByAccountByTerminal(RateQuoteByAccountByTerminal $parameters)"
}
PHP代码:
<?php
$wsdlURL = "https://webservices.example.com/rating/quote.asmx?wsdl";
$username = "user";
$password = "pass";
//Prepare SoapHeader parameters
$cred = array(
'UserName' => $username,
'Password' => $password,
'Site' => ''
);
$params = array (
'location' => "https://webservices.example.com/ratequote",
'uri' => "https://webservices.example.com/",
'trace' => "1",
'exceptions' => "true"
);
$client = new SoapClient($wsdlURL,$params);
$header = new SoapHeader($wsdlURL, 'AuthenticationHeader', $cred);
$client->__setSoapHeaders($header);
$counter = 0;
$params = array(
"QuoteRequest" => array(
"Pieces" => '0',
"ShipDate" => '2014-09-19'
),
);
$return = $client->RateQuote(array('request'=>$params));
?>
WDSL:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="https://webservices.example.com/ratequote/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="https://webservices.example.com/ratequote/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="https://webservices.example.com/ratequote/">
<s:element name="RateQuote">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="request" type="tns:QuoteRequest"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="QuoteRequest">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="OriginZip" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="DestinationZip" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="ShipmentDetails" type="tns:ArrayOfShipmentDetail"/>
<s:element minOccurs="0" maxOccurs="1" name="OriginType" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="PaymentType" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="PalletCount" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="LinearFeet" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="CubicFeet" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="Pieces" type="s:int"/>
<s:element minOccurs="0" maxOccurs="1" name="ServiceDeliveryOptions" type="tns:ArrayOfServiceOptions"/>
<s:element minOccurs="0" maxOccurs="1" name="COD" type="tns:CODFee"/>
<s:element minOccurs="0" maxOccurs="1" name="Discount" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="ListedConsigneeCity" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="InternalUse" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="PalletPosition" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="ShipDate" type="s:dateTime"/>
</s:sequence>
</s:complexType>
<s:complexType name="ArrayOfShipmentDetail">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="ShipmentDetail" nillable="true" type="tns:ShipmentDetail"/>
</s:sequence>
</s:complexType>
<s:complexType name="ShipmentDetail">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="ActualClass" type="s:double"/>
<s:element minOccurs="1" maxOccurs="1" name="Weight" type="s:int"/>
</s:sequence>
</s:complexType>
<s:complexType name="ArrayOfServiceOptions">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="ServiceOptions" nillable="true" type="tns:ServiceOptions"/>
</s:sequence>
</s:complexType>
<s:complexType name="ServiceOptions">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="ServiceCode" type="s:string"/>
</s:sequence>
</s:complexType>
<s:complexType name="CODFee">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="Prepaid" type="s:boolean"/>
<s:element minOccurs="1" maxOccurs="1" name="CODAmount" type="s:double"/>
</s:sequence>
</s:complexType>
<s:element name="RateQuoteResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="RateQuoteResult" type="tns:QuoteResponse"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="QuoteResponse">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="QuoteNumber" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="NetCharge" type="s:double"/>
<s:element minOccurs="0" maxOccurs="1" name="Customer" type="tns:CustomerInformation"/>
<s:element minOccurs="0" maxOccurs="1" name="RoutingInfo" type="tns:RoutingInformation"/>
<s:element minOccurs="0" maxOccurs="1" name="RateDetails" type="tns:ArrayOfQuoteDetail"/>
<s:element minOccurs="0" maxOccurs="1" name="OriginType" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="PaymentType" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="CODAmount" type="s:double"/>
<s:element minOccurs="1" maxOccurs="1" name="ShipmentDate" type="s:dateTime"/>
<s:element minOccurs="1" maxOccurs="1" name="CustomerCubicFoot" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="HawaiianRatedCubicFoot" type="s:int"/>
</s:sequence>
</s:complexType>
<s:complexType name="CustomerInformation">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="AccountNumber" type="s:int"/>
<s:element minOccurs="0" maxOccurs="1" name="Name" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Address1" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Address2" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="City" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="State" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="ZipCode" type="s:string"/>
</s:sequence>
</s:complexType>
<s:complexType name="RoutingInformation">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="DestinationState" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="DestinationZip" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="OriginState" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="OriginZip" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="EstimatedTransitDays" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="OriginTerminal" type="s:string"/>
</s:sequence>
</s:complexType>
<s:complexType name="ArrayOfQuoteDetail">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="QuoteDetail" nillable="true" type="tns:QuoteDetail"/>
</s:sequence>
</s:complexType>
<s:complexType name="QuoteDetail">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="ActualClass" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="RatedClass" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="Charge" type="s:double"/>
<s:element minOccurs="0" maxOccurs="1" name="Code" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Description" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="Rate" type="s:double"/>
<s:element minOccurs="0" maxOccurs="1" name="Weight" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="ExtraMessages" type="s:string"/>
</s:sequence>
</s:complexType>
<s:element name="AuthenticationHeader" type="tns:AuthenticationHeader"/>
<s:complexType name="AuthenticationHeader">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="UserName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Site" type="s:string"/>
</s:sequence>
<s:anyAttribute/>
</s:complexType>
<s:element name="RateQuoteByAccount">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="request" type="tns:QuoteAccountRequest"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="QuoteAccountRequest">
<s:complexContent mixed="false">
<s:extension base="tns:QuoteRequest">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="Account" type="s:int"/>
</s:sequence>
</s:extension>
</s:complexContent>
</s:complexType>
<s:element name="RateQuoteByAccountResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="RateQuoteByAccountResult" type="tns:QuoteResponse"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="RateQuoteByAccountByTerminal">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="request" type="tns:QuoteAccountByTerminalRequest"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="QuoteAccountByTerminalRequest">
<s:complexContent mixed="false">
<s:extension base="tns:QuoteAccountRequest">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="TerminalCode" type="s:string"/>
</s:sequence>
</s:extension>
</s:complexContent>
</s:complexType>
<s:element name="RateQuoteByAccountByTerminalResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="RateQuoteByAccountByTerminalResult" type="tns:QuoteResponse"/>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="RateQuoteSoapIn">
<wsdl:part name="parameters" element="tns:RateQuote"/>
</wsdl:message>
<wsdl:message name="RateQuoteSoapOut">
<wsdl:part name="parameters" element="tns:RateQuoteResponse"/>
</wsdl:message>
<wsdl:message name="RateQuoteAuthenticationHeader">
<wsdl:part name="AuthenticationHeader" element="tns:AuthenticationHeader"/>
</wsdl:message>
<wsdl:message name="RateQuoteByAccountSoapIn">
<wsdl:part name="parameters" element="tns:RateQuoteByAccount"/>
</wsdl:message>
<wsdl:message name="RateQuoteByAccountSoapOut">
<wsdl:part name="parameters" element="tns:RateQuoteByAccountResponse"/>
</wsdl:message>
<wsdl:message name="RateQuoteByAccountAuthenticationHeader">
<wsdl:part name="AuthenticationHeader" element="tns:AuthenticationHeader"/>
</wsdl:message>
<wsdl:message name="RateQuoteByAccountByTerminalSoapIn">
<wsdl:part name="parameters" element="tns:RateQuoteByAccountByTerminal"/>
</wsdl:message>
<wsdl:message name="RateQuoteByAccountByTerminalSoapOut">
<wsdl:part name="parameters" element="tns:RateQuoteByAccountByTerminalResponse"/>
</wsdl:message>
<wsdl:message name="RateQuoteByAccountByTerminalAuthenticationHeader">
<wsdl:part name="AuthenticationHeader" element="tns:AuthenticationHeader"/>
</wsdl:message>
<wsdl:portType name="RateQuoteSoap">
<wsdl:operation name="RateQuote">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">This method sends back a rate quote from the Road Runner Transportation Services System</wsdl:documentation>
<wsdl:input message="tns:RateQuoteSoapIn"/>
<wsdl:output message="tns:RateQuoteSoapOut"/>
</wsdl:operation>
<wsdl:operation name="RateQuoteByAccount">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">This method sends back a rate quote from the Road Runner Transportation Services System</wsdl:documentation>
<wsdl:input message="tns:RateQuoteByAccountSoapIn"/>
<wsdl:output message="tns:RateQuoteByAccountSoapOut"/>
</wsdl:operation>
<wsdl:operation name="RateQuoteByAccountByTerminal">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">This method sends back a rate quote from the Road Runner Transportation Services System</wsdl:documentation>
<wsdl:input message="tns:RateQuoteByAccountByTerminalSoapIn"/>
<wsdl:output message="tns:RateQuoteByAccountByTerminalSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="RateQuoteSoap" type="tns:RateQuoteSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="RateQuote">
<soap:operation soapAction="https://webservices.example.com/ratequote/RateQuote" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
<soap:header message="tns:RateQuoteAuthenticationHeader" part="AuthenticationHeader" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="RateQuoteByAccount">
<soap:operation soapAction="https://webservices.example.com/ratequote/RateQuoteByAccount" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
<soap:header message="tns:RateQuoteByAccountAuthenticationHeader" part="AuthenticationHeader" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="RateQuoteByAccountByTerminal">
<soap:operation soapAction="https://webservices.example.com/ratequote/RateQuoteByAccountByTerminal" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
<soap:header message="tns:RateQuoteByAccountByTerminalAuthenticationHeader" part="AuthenticationHeader" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="RateQuoteSoap12" type="tns:RateQuoteSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="RateQuote">
<soap12:operation soapAction="https://webservices.example.com/ratequote/RateQuote" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
<soap12:header message="tns:RateQuoteAuthenticationHeader" part="AuthenticationHeader" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="RateQuoteByAccount">
<soap12:operation soapAction="https://webservices.example.com/ratequote/RateQuoteByAccount" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
<soap12:header message="tns:RateQuoteByAccountAuthenticationHeader" part="AuthenticationHeader" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="RateQuoteByAccountByTerminal">
<soap12:operation soapAction="https://webservices.example.com/ratequote/RateQuoteByAccountByTerminal" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
<soap12:header message="tns:RateQuoteByAccountByTerminalAuthenticationHeader" part="AuthenticationHeader" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="RateQuote">
<wsdl:port name="RateQuoteSoap" binding="tns:RateQuoteSoap">
<soap:address location="https://webservices.example.com/rating/ratequote.asmx"/>
</wsdl:port>
<wsdl:port name="RateQuoteSoap12" binding="tns:RateQuoteSoap12">
<soap12:address location="https://webservices.example.com/rating/ratequote.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
答案 0 :(得分:0)
错误所涉及的行似乎甚至不存在于您发布的代码中,因此它不是那段代码。
我不知道SoapClient :: RateQuote()的作用,但听起来它需要传递给数组的值,并将这些值分配给对象的属性。 (错误消息使用术语&#34;属性&#34;具体表示对象/类变量,而不仅仅是数组键。)所以听起来像QuoteRequest对象没有$ Pieces属性(类变量)。
这在黑暗中有点像SWAG。
我看到的另一件事是,在WSDL中,Pieces是一个int,但是你传入一个字符串。在PHP中它通常并不重要,但它在内部确实很重要,并且可能与SoapClient期望的内容发生冲突。尝试将"Pieces" => '0'
仅传递为"Pieces" => 0
。