我想打电话给网络服务。 webservice包含一些复杂类型元素。我用ASP.NET和soapUI获得了很好的结果。但是我的PHP出错了。我想不出来。
那么,你能帮帮我吗?
感谢。
我想要调用的函数:
<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代码(它正在运行):
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):
<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代码(它没有工作):
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
使用try and catch:
End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 155.
答案 0 :(得分:1)
所以,我试图重新创建你的问题,因为我没有访问你的服务我选择Temperature Conversion,直到我添加
$SoapCallParameters = new stdClass();
$SoapCallParameters->nCelcius = 30;
$obj = $client->CelciusToFahrenheit($SoapCallParameters);
也许您也可以尝试使用类似
的stdClass$hotelSearch = new stdClass();
$hotelSearch->searchClass->BRANCHID = 000;
$hotelSearch->searchClass->UNIQUECODE = YIO;
免责声明:你应该知道我正在学习php,我学习的唯一方法就是解决问题,所以这就是我试图解决问题。
我的工作温度转换工作代码如下:
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的帮助