我正在请求服务。
链接到wsdl文件wsdl
这是代码
$client = new SoapClient("http://zelsoft.ru/intourxml_v2/BookingService.asmx?WSDL", array(
'soap_version'=> SOAP_1_2,
'exceptions' => 1,
));
$xml = <<<XML
<GetReferenceRq>
<Login>Zelsoft</Login>
<Password>zel123</Password>
<Countries>true</Countries>
<Regions>true</Regions>
</GetReferenceRq>
XML;
$struct = new SoapVar($xml,XSD_ANYXML,"GetReferenceRq");
try{
echo "<pre>";
print_r($client->__getFunctions());
print_r($client->GetReference($struct));
echo "</pre>";
} catch(Exception $e){
echo $e->getMessage();
}
但是我得到一个错误
Function ("GetReference") is not a valid method for this service
$client->__getFunctions()
表示方法存在
谢谢你的回答
更新我用肥皂解决了这个问题。Wsdl_cache_enabled设置为0,但出现另一个问题
我正在用这样的代码发送请求
$client = new SoapClient("http://zelsoft.ru/intourxml_v2/BookingService.asmx?WSDL", array(
'soap_version'=> SOAP_1_2,
'exceptions' => 1,
));
class GetReferenceRq{
public $Login = 'Zelsoft';
public $Password = 'zel123';
}
try{
echo "<pre>";
print_r($client->GetReference(new GetReferenceRq()));
echo "</pre>";
} catch(Exception $e){
echo $e->getMessage();
}
但得到响应
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Zelsoft.InTourXML.BusinessLogic.Base.GetBaseRqParams(SqlConnection cnn, BaseRq rq)
at Zelsoft.InTourXML.BusinessLogic.Base.Connect(BaseRq rq)
at Zelsoft.InTourXML.BusinessLogic.Reference.GetReference(GetReferenceRq rq)
at Zelsoft.InTourXML.BookingService.GetReference(GetReferenceRq rq)
--- End of inner exception stack trace ---
在WSDL
的GetReferenceRq
数据类型上似乎没有Login或Password字段。我将向您展示我是如何得出这个结论的,也许它会给其他人一些关于如何排除SOAP
的线索。
从$client->__getFunctions()
输出中,您可以看到GetReference的API签名:
array(38) {
[0]=>
string(59) "GetReferenceResponse GetReference(GetReference $parameters)"
这告诉您方法GetReference()
接受一个名为$parameters
的参数,该参数需要为GetReference
类型。您可以通过执行$client->__getTypes()
:
array(157) {
[0]=>
string(43) "struct GetReference {
GetReferenceRq rq;
}"
[1]=>
string(569) "struct GetReferenceRq {
boolean Countries;
boolean Regions;
boolean Cities;
boolean Districts;
boolean Meals;
boolean Currencies;
boolean HotelServices;
boolean HotelCategories;
boolean Hotels;
boolean Genders;
boolean RoomTypes;
boolean RoomCategories;
boolean AccommodationTypes;
boolean BookingStatuses;
boolean TransferPointTypes;
boolean TransferPoints;
boolean TransferTypes;
boolean Attractions;
boolean Languages;
boolean HotelChains;
boolean Flights;
boolean TourTypes;
boolean TourDirections;
int CountryId;
int CityId;
int TypeId;
}"
所以你需要创建一个包含GetReferenceRq的类。您的代码需要看起来像:
$client = new SoapClient("http://zelsoft.ru/intourxml_v2/BookingService.asmx?WSDL", array(
'soap_version'=> SOAP_1_2,
'exceptions' => 1,
));
class GetReference {
public $rq;
}
class GetReferenceRq{
public $Login = 'Zelsoft';
public $Password = 'zel123';
}
$parameters = new GetReference();
$parameters->rq = new GetReferenceRq();
try{
echo "<pre>";
print_r($client->GetReference($parameters));
echo "</pre>";
} catch(Exception $e){
echo $e->getMessage();
}
但是你现在有新的错误:object has no 'Countries' property
。实际上,在GetReferenceRq
类型中没有Login和Password字段。相反,您必须添加国家,地区等。
如果web服务需要身份验证,您必须参考文档来了解它是如何工作的。