PHP Soap服务器:can';t访问被调用类中的soap请求参数


PHP Soap Server : can't access to soap request parameters in my called class

我无法访问参数(认为一切似乎都很好,没有返回错误):

<?php
// Class that is called by soap server handle function
class MyClass {
  // function that correspond to operation name in wsdl file
  public function MdBSpieGetInformationPasseport($myParam) {
  // This code is well executed
  // But how can i read here IDENTIFIANT parameter ?
  // It seems there's nothing in $myParam
  // I know i can read $HTTP_RAW_POST_DATA here 
  // but it should have been parsed automatically, no ?
  }
}

$server = new SoapServer('testWs.wsdl');
$server->setClass('MyClass');
$server->handle();
?>

以下是wsdl文件(testWs.wsdl):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="wsTest" xmlns:spie="wsTest">
  <wsdl:types>
    <xsd:schema>
      <xsd:import schemaLocation="http://testws.local/?pg=xsd" namespace="wsTest" />
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="MdBSpieGetInformationPasseportInput">
    <wsdl:part element="spie:MdBSpieBovinRequest" name="parameters"/>
  </wsdl:message>
  <wsdl:message name="MdBSpieGetInformationPasseportOutput">
    <wsdl:part element="spie:MdBSpieGetInformationPasseportResponse" name="parameters"/>
  </wsdl:message>
  <wsdl:portType name="wsTestPortType">
    <wsdl:operation name="MdBSpieGetInformationPasseport">
      <wsdl:input message="spie:MdBSpieGetInformationPasseportInput"/>
      <wsdl:output message="spie:MdBSpieGetInformationPasseportOutput"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="wsTestBinding" type="spie:wsTestPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="MdBSpieGetInformationPasseport">
      <soap:operation soapAction="http://testWs.local/?pg=ws"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="wsTest">
    <wsdl:port name="wsTestBinding" binding="spie:wsTestBinding">
      <soap:address location="http://testWs.local/?pg=ws" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

以及嵌入的testWs.xsd文件:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:spie="wsTest" targetNamespace="wsTest" elementFormDefault="qualified">
   <xsd:element name="MdBSpieBovinRequest">
      <xsd:complexType>
         <xsd:sequence>
            <xsd:element name="Authentification" type="spie:typeAuthentificationRequest"/>
            <xsd:element name="Bovin" type="spie:typeBovinRequest"/>
         </xsd:sequence>
      </xsd:complexType>
   </xsd:element>
   <xsd:complexType name="typeAuthentificationRequest">
      <xsd:sequence>
         <xsd:element name="IDENTIFIANT">
            <xsd:simpleType>
               <xsd:restriction base="xsd:string">
                  <xsd:length value="20"/>
               </xsd:restriction>
            </xsd:simpleType>
         </xsd:element>
         <xsd:element name="MOT_DE_PASSE">
            <xsd:simpleType>
               <xsd:restriction base="xsd:string">
                  <xsd:maxLength value="12"/>
               </xsd:restriction>
            </xsd:simpleType>
         </xsd:element>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:complexType name="typeBovinRequest">
      <xsd:sequence>
         <xsd:element name="CODE_PAYS">
            <xsd:simpleType>
               <xsd:restriction base="xsd:string">
                  <xsd:length value="2" />
               </xsd:restriction>
            </xsd:simpleType>
         </xsd:element>
         <xsd:element name="NUMERO_ANIMAL">
            <xsd:simpleType>
               <xsd:restriction base="xsd:string">
                  <xsd:maxLength value="12"/>
               </xsd:restriction>
            </xsd:simpleType>
         </xsd:element>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:element name="MdBSpieGetInformationPasseportResponse">
      <xsd:complexType>
         <xsd:sequence>
            <xsd:element name="ReponseStandard" type="spie:typeReponseStandard"/>
            <xsd:element name="ReponseSpecifique" type="spie:typeReponseInformationPasseport" minOccurs="0"/>
         </xsd:sequence>
      </xsd:complexType>
   </xsd:element>
   <xsd:complexType name="typeReponseStandard">
      <xsd:sequence>
         <xsd:element name="Resultat" type="xsd:boolean"/>
         <xsd:element name="Anomalie" type="spie:typeAnomalie" minOccurs="0"/>
      </xsd:sequence>
   </xsd:complexType>

   <xsd:complexType name="typeAnomalie">
      <xsd:sequence>
         <xsd:element name="CODE_ANOMALIE">
            <xsd:simpleType>
               <xsd:restriction base="xsd:string">
                  <xsd:pattern value="/^9MdBSpie/"></xsd:pattern>
               </xsd:restriction>
            </xsd:simpleType>
         </xsd:element>
         <xsd:element name="SEVERITE_ANOMALIE" type="xsd:integer"/>
         <xsd:element name="MESSAGE_ANOMALIE" type="xsd:string"/>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:complexType name="typeReponseInformationPasseport">
      <xsd:sequence>
         <xsd:element name="NUTRAV">
            <xsd:simpleType>
               <xsd:restriction base="xsd:string">
                  <xsd:length value="4"/>
               </xsd:restriction>
            </xsd:simpleType>
         </xsd:element>
         <xsd:element name="COPAIP">
            <xsd:simpleType>
               <xsd:restriction base="xsd:string">
                  <xsd:length value="2"/>
               </xsd:restriction>
            </xsd:simpleType>
         </xsd:element>
         <xsd:element name="NUNATI">
            <xsd:simpleType>
               <xsd:restriction base="xsd:string">
                  <xsd:maxLength value="12"/>
               </xsd:restriction>
            </xsd:simpleType>
         </xsd:element>
         <xsd:element name="SEXBOV" minOccurs="0">
            <xsd:simpleType>
               <xsd:restriction base="xsd:string">
                  <xsd:length value="1"/>
               </xsd:restriction>
            </xsd:simpleType>
         </xsd:element>
         <xsd:element name="CORABO" minOccurs="0">
            <xsd:simpleType>
               <xsd:restriction base="xsd:string">
                  <xsd:length value="2"/>
               </xsd:restriction>
            </xsd:simpleType>
         </xsd:element>
         <xsd:element name="DANAIS" type="xsd:date" minOccurs="0"/>
      </xsd:sequence>
   </xsd:complexType>
</xsd:schema>

我使用SoapUI发送soap请求。以下是我在SoapUI请求窗口中看到的内容:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wst="wsTest">
   <soapenv:Header/>
   <soapenv:Body>
      <wst:MdBSpieBovinRequest>
         <wst:Authentification>
            <wst:IDENTIFIANT>soapid</wst:IDENTIFIANT>
            <wst:MOT_DE_PASSE>soappasswd</wst:MOT_DE_PASSE>
         </wst:Authentification>
         <wst:Bovin>
            <wst:CODE_PAYS>soappays</wst:CODE_PAYS>
            <wst:NUMERO_ANIMAL>soapanimal</wst:NUMERO_ANIMAL>
         </wst:Bovin>
      </wst:MdBSpieBovinRequest>
   </soapenv:Body>
</soapenv:Envelope>

注意wst:出现了,我不知道它是从哪里来的。我的sdl文件中有错误吗?

在SoapUI响应窗口中:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="wsTest">
   <SOAP-ENV:Body>
      <ns1:MdBSpieGetInformationPasseportResponse/>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

感谢您帮助

PHP 5.3.9

编辑:第一个错误出现在SoapServer通知中(http://www.php.net/manual/fr/soapserver.soapserver.php#102143):

$server = new 'SoapServer('http://myprojet.local?wsdl'); // correct

这是我的PHP,正在工作:

<?php
$client = new SoapClient("http://localhost/code/soap.wsdl");
$something =  $client->HelloWorld(array());
echo $something->HelloWorldResult;
die();
?>

感谢Thierry,

这是我根据你的建议使用的,对我有效:

    $server = new SoapServer(null,array('uri' => $serviceURL));

谨致问候,Daniel