1

我想打电话给网络服务。并且网络服务包含一些复杂类型的元素。我用 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 

尝试并抓住:

End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 155.
4

1 回答 1

1

所以,我试图重现您的问题,但由于我无法访问您的服务,所以我选择了温度转换,它在我添加之前不起作用

$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 的帮助

运行soapclient时出现内部服务器错误

于 2013-09-13T22:27:17.997 回答