PHP Soap Server:无法访问我所调用类中的soap请求参数 [英] PHP Soap Server : can't access to soap request parameters in my called class

查看:92
本文介绍了PHP Soap Server:无法访问我所调用类中的soap请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I can't access to parameters (thought everything seems to be fine, no error returned) :

<?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):

Here is the wsdl file (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文件:

And the testWs.xsd file embedded :

<?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发送肥皂请求.这是我在SoapUI请求窗口中看到的:

I use SoapUI to send soap request. Here is what i see in SoapUI request window :

<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文件是否存在错误?

Notice that wst: appeared and i don't know where it comes from. Is there an error in my sdl file ?

在SoapUI响应窗口中:

And in SoapUI response window :

<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

PHP 5.3.9

第一个错误是SoapServer实例( http://www.php.net/manual/fr/soapserver.soapserver.php#102143 ):

EDIT : First error was in SoapServer instanciation (http://www.php.net/manual/fr/soapserver.soapserver.php#102143) :

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

推荐答案

这是我的PHP,可以正常工作:

Here is my PHP, working:

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

?>

这篇关于PHP Soap Server:无法访问我所调用类中的soap请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆