[英]PHP SOAP Issue : Object reference not set to an instance of an object
I'm trying to build an interface to https://ws.farebuzz.com/FlightGateway.asmx?WSDL using php and SoapClient class. 我正在尝试使用php和SoapClient类构建https://ws.farebuzz.com/FlightGateway.asmx?WSDL的界面。
I managed to get over the authentication header but I'm stuck when I try to call a method .. I'm always getting : 我设法克服了身份验证标题,但是当我尝试调用方法时我被卡住了......我总是得到:
Uncaught SoapFault exception: [soap:Server] Server was unable to process request. 未捕获的SoapFault异常:[soap:Server]服务器无法处理请求。 ---> Object reference not set to an instance of an object.
--->对象引用未设置为对象的实例。
I tried calling it like this (as an object) : 我尝试像这样(作为对象)调用它:
class SearchFlights{
public $NumberOfAdults;
public $ClassOfService;
public $TypeOfTrip;
public $FromCity;
public $ToCity;
}
$parameters = new SearchFlights();
$parameters->NumberOfAdults = 2;
$parameters->ClassOfService = 'ECONOMY';
$parameters->FromCity = 'ECONOMY';
$parameters->ToCity = '1te';
$parameters->TypeOfTrip = 'NONE';
$this->client->SearchFlights($parameters);
and as an array like : 并作为一个数组:
$parameters = array('ToCity' => 'testttt',...);
but I got same error. 但我得到了同样的错误。 Can anyone help?
有人可以帮忙吗?
Thanks 谢谢
Sorin 索林
Your WSDL states that it has to be called in this way: 您的WSDL声明必须以这种方式调用它:
$this->client->SearchFlights(array('searchRequest' => $parameters));
Note that the searchRequest
name is important . 请注意,
searchRequest
名称很重要 。
There are also various mandatory inputs for that service, you should ensure that those are present. 该服务还有各种强制性输入,您应该确保它们存在。 From looking at your code, you are missing some.
从查看代码开始,您就会遗漏一些代码。
Take a look at the FlightSearchRequest
complex type here. 在这里查看
FlightSearchRequest
复杂类型。 Each param that has minOccurs=1
is required. 每个需要
minOccurs=1
参数都是必需的。
<s:complexType name="FlightSearchRequest">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="TypeOfTrip" type="tns:TripType"/>
<s:element minOccurs="0" maxOccurs="1" name="FromCity" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="ToCity" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="ReturnFromCity" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="ReturnToCity" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="DepartureDate" type="s:dateTime"/>
<s:element minOccurs="1" maxOccurs="1" name="ReturnDate" type="s:dateTime"/>
<s:element minOccurs="1" maxOccurs="1" name="NumberOfAdults" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="NumberOfChildren" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="NumberOfInfantsInLap" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="NumberOfInfantsOnSeat" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="NumberOfSeniors" type="s:int"/>
<s:element minOccurs="0" maxOccurs="1" name="AirlinePreference" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="ClassOfService" type="tns:FlightClass"/>
<s:element minOccurs="1" maxOccurs="1" name="IsNonStop" type="s:boolean"/>
<s:element minOccurs="1" maxOccurs="1" name="ConsolidatorFaresOnly" type="s:boolean"/>
<s:element minOccurs="0" maxOccurs="1" name="FpAffiliate" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="FpSubAffiliate" type="s:string"/>
</s:sequence>
</s:complexType>
Try using this: 试试这个:
$this->client->SearchFlights(array('parameters' => $parameters));
I was having problems trying to access a .net webservice and this solved it for me. 我在尝试访问.net webservice时遇到了问题,这为我解决了这个问题。
I was also curious to know the answer of this question and finally i got to know the reason of this: The nodes which we are sending through SOAP request should be known to us with Data types and whether they are compulsory or not. 我也很想知道这个问题的答案,最后我知道了这个的原因:我们通过SOAP请求发送的节点应该为我们提供数据类型以及它们是否是强制的。 So here if any of these nodes followed by strict instructions of that WSDL shouldn't be followed we will get the error which will say that the "Object reference not set to an instance of an object".
因此,如果这些节点中的任何一个遵循该WSDL的严格指令不应该被遵循,那么我们将得到错误,该错误将“对象引用未设置为对象的实例”。 I will give you an example which i faced: I was having the same issue, and i got to know that i wasn't sending any value to a node, which was excepting at least one value or one occurrence of it, then i validate it on my end, if successful i was sending that value otherwise empty string, which was telling that WSDL that this is at least 1 occurrence and has a value.
我将给你一个我面临的例子:我遇到了同样的问题,我知道我没有向节点发送任何值,除了至少一个值或一次出现,然后我验证它在我的最后,如果成功我发送该值否则为空字符串,这告诉WSDL这至少是1次出现并且有一个值。 Finally i got resolved this bug.
最后我解决了这个bug。 Baseline here is, if the nodes those are compulsory and did not send perfectly will raise into this exception or else send empty string into those nodes.
这里的基线是,如果那些是强制的并且没有完美发送的节点将引发此异常,或者将空字符串发送到这些节点。 Thanks
谢谢
If I understand the WSDL correctly, the SearchFlights object is supposed to contain a FlightSearchRequest object. 如果我正确理解WSDL,则SearchFlights对象应该包含FlightSearchRequest对象。 It is the latter that contains the parameters.
后者包含参数。
Try this: 试试这个:
$parameters->FlightSearchRequest->NumberOfAdults = 2;
$parameters->FlightSearchRequest->ClassOfService = 'ECONOMY';
// etc...
$this->client->SearchFlights($parameters);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.