0

我在 PHP 中的 SOAP 客户端有问题,我认为我的请求是正确的。

我的 PHP 客户端 SOAP:

$soapURL = "http://mylink.fr/mywsdl?wsdl";
$soapParameters = Array('login' => "MyLogin", 'password' => "MyPassword", 'trace' => 1);
try {

   $service=new SoapClient($soapURL, $soapParameters);

   $request = array(
      'address' => array(
         'city' => '',
         'country' => '',
         'department' => '',
         'district' => '',
         'houseNumber' => '',
         'region' => '',
         'road' => '',
         'roadNumber' => '',
         'zipCode' => ''
      ),
      'category' => array(
         'logo' => '',
         'name' => '',
         'reference' => ''
      ),
      'companyName' => '',
      'contactMail' => '',
      'contactName' => '',
      'contactPhone' => '',
      'endTemporary' => '2015-02-15T13:00:10',
      'latitude' => 12.0,
      'longitude' => 12.0,
      'name' => '',
      'radius' => 520,
      'reference' => '',
      'startTemporary' => '2015-02-15T13:00:11',
      'temporary' => 0
   );

   $result = $service->createPOI($request);
} catch(SoapFault $e) {

   echo $service->__getLastRequest();
   echo $e->__toString();

}

我的 SOAP 请求:

<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.webservices.masternaut.fr/MasterWS/services/POI" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="urn:POI" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" soap-env:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/">
   <soap-env:body>
      <ns1:createpoi>
         <poi xsi:type="ns2:POI">
            <address xsi:type="ns2:Address">
               <city xsi:type="xsd:string"></city>
               <country xsi:type="xsd:string"></country>
               <department xsi:type="xsd:string"></department>
               <district xsi:type="xsd:string"></district>
               <housenumber xsi:type="xsd:string"></housenumber>
               <region xsi:type="xsd:string"></region>
               <road xsi:type="xsd:string"></road>
               <roadnumber xsi:type="xsd:string"></roadnumber>
               <zipcode xsi:type="xsd:string"></zipcode>
            </address>
            <category xsi:type="ns2:PoiCategory">
               <logo xsi:type="xsd:string"></logo>
               <name xsi:type="xsd:string"></name>
               <reference xsi:type="xsd:string"></reference>
            </category>
            <companyname xsi:type="xsd:string"></companyname>
            <contactmail xsi:type="xsd:string"></contactmail>
            <contactname xsi:type="xsd:string"></contactname>
            <contactphone xsi:type="xsd:string"></contactphone>
            <endtemporary xsi:type="xsd:dateTime">2015-02-15T13:00:10</endtemporary>
            <latitude xsi:type="xsd:double">12</latitude>
            <longitude xsi:type="xsd:double">12</longitude>
            <name xsi:type="xsd:string"></name>
            <radius xsi:type="xsd:int">520</radius>
            <reference xsi:type="xsd:string"></reference>
            <starttemporary xsi:type="xsd:dateTime">2015-02-15T13:00:11</starttemporary>
            <temporary xsi:type="xsd:boolean">false</temporary>
         </poi>
         <overwrite xsi:nil="true"></overwrite>
      </ns1:createpoi>
   </soap-env:body>
</soap-env:envelope>

WSDL:

<complexType name="PoiCategory">
   <sequence>
      <element name="logo" nillable="true" type="xsd:string"/>
      <element name="name" nillable="true" type="xsd:string"/>
      <element name="reference" nillable="true" type="xsd:string"/>
   </sequence>
</complexType>
<complexType name="Address">
   <sequence>
      <element name="city" nillable="true" type="xsd:string"/>
      <element name="country" nillable="true" type="xsd:string"/>
      <element name="department" nillable="true" type="xsd:string"/>
      <element name="district" nillable="true" type="xsd:string"/>
      <element name="houseNumber" nillable="true" type="xsd:string"/>
      <element name="region" nillable="true" type="xsd:string"/>
      <element name="road" nillable="true" type="xsd:string"/>
      <element name="roadNumber" nillable="true" type="xsd:string"/>
      <element name="zipCode" nillable="true" type="xsd:string"/>
   </sequence>
</complexType>
<complexType name="POI">
   <sequence>
      <element name="address" nillable="true" type="tns1:Address"/>
      <element name="category" nillable="true" type="tns1:PoiCategory"/>
      <element name="companyName" nillable="true" type="xsd:string"/>
      <element name="contactMail" nillable="true" type="xsd:string"/>
      <element name="contactName" nillable="true" type="xsd:string"/>
      <element name="contactPhone" nillable="true" type="xsd:string"/>
      <element name="endTemporary" nillable="true" type="xsd:dateTime"/>
      <element name="latitude" type="xsd:double"/>
      <element name="longitude" type="xsd:double"/>
      <element name="name" nillable="true" type="xsd:string"/>
      <element name="radius" type="xsd:int"/>
      <element name="reference" nillable="true" type="xsd:string"/>
      <element name="startTemporary" nillable="true" type="xsd:dateTime"/>
      <element name="temporary" type="xsd:boolean"/>
   </sequence>
</complexType>
<wsdl:portType name="PoiWS">
   <wsdl:message name="createPOIRequest">
      <wsdl:part name="poi" type="tns1:POI"></wsdl:part>
      <wsdl:part name="overwrite" type="xsd:boolean"></wsdl:part>
   </wsdl:message>
   <wsdl:message name="createPOIResponse">
      <wsdl:part name="createPOIReturn" type="xsd:int"></wsdl:part>
   </wsdl:message>
</wsdl:portType>
<wsdl:binding name="POISoapBinding" type="impl:PoiWS">
   <wsdl:operation name="createPOI">
      <wsdlsoap:operation soapAction=""/>
      <wsdl:input name="createPOIRequest">
         <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://mylink.fr/wsdl" use="encoded"/>
      </wsdl:input>
      <wsdl:output name="createPOIResponse">
         <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://mylink.fr/wsdl" use="encoded"/>
      </wsdl:output>
   </wsdl:operation>
</wsdl:binding>
<wsdl:service name="PoiWSService">
   <wsdl:port binding="impl:POISoapBinding" name="POI">
      <wsdlsoap:address location="http://mylink.fr/wsdl"/>
   </wsdl:port>
</wsdl:service>

我收到此错误:

SoapFault exception: [Server.userException] No such operation 'createPOI' in /var/www/devt/cronJobs/test.php:58 
Stack trace: #0 /var/www/devt/cronJobs/test.php(58): SoapClient->__call('createPOI', Array) 
#1 /var/www/devt/cronJobs/test.php(58): SoapClient->createPOI(Array) 
#2 {main}

你能说我的问题在哪里并解释一下吗?

我是 SOAP 的初学者

提前致谢

4

2 回答 2

0

如果您想知道您的 wsdl 支持哪些操作,请始终在 wsdl 中查找端口类型。

wsdl 中的 portType 就像 java 中的类一样,它可以有多个“操作”或 java 世界中的“方法”。

您的 wsdl 有一种端口类型,即 PoiWS,但我看不到其中添加了任何操作。虽然您的绑定引用了应该具有操作 createPOI 的 PoiWS 端口类型,

<wsdl:binding name="POISoapBinding" type="impl:PoiWS">
   <wsdl:operation name="createPOI">

请更正您的 wsdl .. 例如 portType 应该是这样的,

<wsdl:portType name="TestPortType">
    <wsdl:operation name="operationName">
        <wsdl:input name="input" message="tns:input"/>
        <wsdl:output name="output" message="tns:output"/>
    </wsdl:operation>
</wsdl:portType>
于 2015-02-27T10:03:24.603 回答
0

查看 WSDL,您的请求应该是这样的:

 $request = array(
      'address' => array(
         'city' => '',
         'country' => '',
         'department' => '',
         'district' => '',
         'houseNumber' => '',
         'region' => '',
         'road' => '',
         'roadNumber' => '',
         'zipCode' => ''
      ),
      'category' => array(
         'logo' => '',
         'name' => '',
         'reference' => ''
      ),
      'POI' => array(
         'companyName' => '',
         'contactMail' => '',
         'contactName' => '',
         'contactPhone' => '',
         'endTemporary' => '2015-02-15T13:00:10',
         'latitude' => 12.0,
         'longitude' => 12.0,
         'name' => '',
         'radius' => 520,
         'reference' => '',
         'startTemporary' => '2015-02-15T13:00:11',
         'temporary' => 0
       )
   );
于 2015-02-25T14:27:08.680 回答