PHP 和访问 SOAP Web 服务中的 ComplexType [英] PHP and Accessing ComplexType in SOAP Web Service
问题描述
我想调用网络服务.并且 webservice 包含一些 complextype 元素.我使用 ASP.NET 和 soapUI 取得了不错的效果.但是我遇到了 PHP 错误.我想不通.
I want to make a call to a webservice. And the webservice is contain some complextype elements. I'm getting good results with ASP.NET and soapUI. But I'm getting an error with PHP. I couldn't figured out.
那么,你能帮我吗?
谢谢.
我要调用的函数:
<xs:element name="GetHotelSearch">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="searchClass" nillable="true" type="q13:HotelSearch" xmlns:q13="http://schemas.datacontract.org/2004/07/Model"/>
<xs:element minOccurs="0" name="recorCount" type="xs:int"/>
<xs:element minOccurs="0" name="sortType" type="q14:SortType" xmlns:q14="http://schemas.datacontract.org/2004/07/Model"/>
<xs:element minOccurs="0" name="sortFields" nillable="true" type="q15:ArrayOfSortField" xmlns:q15="http://schemas.datacontract.org/2004/07/Model"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetHotelSearchResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="GetHotelSearchResult" nillable="true" type="q16:ArrayOfHotelSummary" xmlns:q16="http://schemas.datacontract.org/2004/07/Model"/>
<xs:element minOccurs="0" name="recorCount" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
复杂类型:
<xs:complexType name="HotelSearch">
<xs:sequence>
<xs:element minOccurs="0" name="BRANCHID" type="xs:int"/>
<xs:element minOccurs="0" name="UNIQUECODE" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="SortType">
<xs:restriction base="xs:string">
<xs:enumeration value="Ascending">
<xs:annotation>
<xs:appinfo>
<EnumerationValue xmlns="http://schemas.microsoft.com/2003/10/Serialization/">1</EnumerationValue>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="Descending">
<xs:annotation>
<xs:appinfo>
<EnumerationValue xmlns="http://schemas.microsoft.com/2003/10/Serialization/">2</EnumerationValue>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:element name="SortType" nillable="true" type="tns:SortType"/>
<xs:complexType name="ArrayOfSortField">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="SortField" type="tns:SortField"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfSortField" nillable="true" type="tns:ArrayOfSortField"/>
<xs:simpleType name="SortField">
<xs:restriction base="xs:string">
<xs:enumeration value="PENSIONTYPENAME">
<xs:annotation>
<xs:appinfo>
<EnumerationValue xmlns="http://schemas.microsoft.com/2003/10/Serialization/">1</EnumerationValue>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="HOTELNAME">
<xs:annotation>
<xs:appinfo>
<EnumerationValue xmlns="http://schemas.microsoft.com/2003/10/Serialization/">2</EnumerationValue>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:element name="SortField" nillable="true" type="tns:SortField"/>
.NET 代码(正在运行):
.NET Code (it's working):
int _recordCount = 10;
List<HotelSummary> hotels = hc.GetHotelSearch(new HotelSearch()
{
BRANCHID = 000,
UNIQUECODE = "YIO"
}, ref _recordCount, SortType.Ascending, new SortField[] { SortField.HOTELNAME }).ToList();
XML(它与soapUI 一起工作):
The XML (it's working with soapUI):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:mod="http://schemas.datacontract.org/2004/07/Model">
<soapenv:Header/>
<soapenv:Body>
<tem:GetHotelSearch>
<tem:searchClass>
<mod:BRANCHID>000</mod:BRANCHID>
<mod:UNIQUECODE>YIO</mod:UNIQUECODE>
</tem:searchClass>
<tem:recorCount>10</tem:recorCount>
<tem:sortType>Ascending</tem:sortType>
<tem:sortFields>
<mod:SortField>HOTELNAME</mod:SortField>
</tem:sortFields>
</tem:GetHotelSearch>
</soapenv:Body>
</soapenv:Envelope>
和 PHP 代码(不起作用):
And PHP Code (It's not WORKING):
ini_set("soap.wsdl_cache_enabled", "0");
$url='http://localhost/Service/Service.svc?wsdl';
$client = new SoapClient($url);
$HotelSearch= array('BRANCHID' => 000,'UNIQUECODE' => 'YIO');
$SortField= array('SortField' => 'HOTELNAME');
$result = $client->GetHotelSearch($HotelSearch, 10, 'Ascending', $SortField);
$array = $result->GetHotelSearchResult->HotelSummary;
我收到此错误:
Fatal error: Uncaught SoapFault exception: [a:InternalServiceFault] End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 155. in D:\[.Projeler]\musteri\webservis\test.php:98 Stack trace: #0 D:\[.Projeler]\musteri\webservis\test.php(98): SoapClient->__call('GetHotelSearch', Array) #1 D:\[.Projeler]\musteri\webservis\test.php(98): SoapClient->GetHotelSearch(Array, 10, 'Ascending', Object(stdClass)) #2 {main} thrown in D:\[.Projeler]\musteri\webservis\test.php on line 98
尝试和捕获:
End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 155.
推荐答案
所以,我试图重现您的问题,但由于我无法访问您的服务,我选择了 温度转换 直到我添加
So, I tried to recreate your problem and as i didn't have access to your service i choose Temperature Conversion which did not work till i added
$SoapCallParameters = new stdClass();
$SoapCallParameters->nCelcius = 30;
$obj = $client->CelciusToFahrenheit($SoapCallParameters);
也许你也可以尝试使用 stdClass 之类的东西
maybe you could also try using the stdClass something like
$hotelSearch = new stdClass();
$hotelSearch->searchClass->BRANCHID = 000;
$hotelSearch->searchClass->UNIQUECODE = YIO;
免责声明:你应该知道我正在学习 php,我学习的唯一方法就是解决问题,所以这是我试图解决一个问题.
DISCLAIMER: You should know that i am learning php and the only way i learn is by solving problems, so this is me trying to solve a problem.
我的工作温度转换工作代码如下:
my working temperature conversion working code is below:
error_reporting(E_ALL);
ini_set('display_errors', '1');
$url = "http://webservices.daehosting.com/services/TemperatureConversions.wso?WSDL";
$client = new SoapClient($url, array("trace" => 1, "exception" => 0));
var_dump($client->__getFunctions());
$SOAPCall = "CelciusToFahrenheit";
$SoapCallParameters = new stdClass();
$SoapCallParameters->nCelcius = 30;
$obj = $client->CelciusToFahrenheit($SoapCallParameters);
var_dump($obj);
我得到了@Sergiu Paraschiv 的帮助
I had help from @Sergiu Paraschiv
这篇关于PHP 和访问 SOAP Web 服务中的 ComplexType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!