2011-06-16 34 views
0

我的SOAP服务器(打算设置)有三个操作:登录,注销和版本。PHP SoapServer总是调用相同的函数,尽管调用了不同的函数

登录函数的代码当前正在“伪造”它,接受两个参数,一个用户名和密码,通过将它们存储在函数类的专用用户名和密码变量中自动“验证”它们。我有一个会议开始在Web服务行动的切入点,并在初始化时的SoapServer的设置功能上课的时候,我坚持连接如下:

 $this->setClass('WebSvcSoapFunctions'); 
     $this->setPersistence(SOAP_PERSISTENCE_SESSION); 

当我创建一个SOAP客户端和电话我的服务,无论调用哪个函数,看起来version()函数总是被执行,而不是被调用的函数。我想这可能是由于我的WSDL的书写方式,但我看不出有问题(我是新)....

我有以下WSDL通过PHP SoapServer时听:

<?xml version="1.0" encoding="UTF-8"?> 

<wsdl:types> 

    <schema xmlns:rns="http://soap.jrimer-amp64/" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://soap.jrimer-amp64/" version="1.0.0" elementFormDefault="unqualified" attributeFormDefault="unqualified"> 

     <complexType name="versionRequest"> 
     </complexType> 

     <complexType name="versionResponse"> 
      <sequence> 
       <element name="result" type="string" minOccurs="1"/> 
      </sequence> 
     </complexType> 

     <complexType name="loginRequest"> 
      <sequence> 
       <element name="username" type="string" use="required"/> 
       <element name="password" type="string" use="required"/> 
      </sequence> 
     </complexType> 

     <complexType name="loginResponse"> 
      <sequence> 
       <element name="result" type="string" minOccurs="1"/> 
      </sequence> 
     </complexType> 

     <complexType name="logoutRequest"> 
     </complexType> 

     <complexType name="logoutResponse"> 
      <sequence> 
       <element name="result" type="string" minOccurs="1"/> 
      </sequence> 
     </complexType> 

    </schema> 

</wsdl:types> 


<wsdl:service name="XxxxxxSvc"> 

    <wsdl:port name="XxxxxxSvc-Endpoint0" binding="tns:XxxxxxSvc-Endpoint0Binding"> 
     <soap:address location="http://soap.jrimer-amp64/"/> 
    </wsdl:port> 

</wsdl:service> 


<wsdl:portType name="portType"> 

    <wsdl:operation name="version"> 
     <wsdl:input message="tns:versionRequest"/> 
     <wsdl:output message="tns:versionResponse"/> 
    </wsdl:operation> 
    <wsdl:operation name="login"> 
     <wsdl:input message="tns:loginRequest"/> 
     <wsdl:output message="tns:loginResponse"/> 
    </wsdl:operation> 
    <wsdl:operation name="logout"> 
     <wsdl:input message="tns:logoutRequest"/> 
     <wsdl:output message="tns:logoutResponse"/> 
    </wsdl:operation> 

</wsdl:portType> 


<wsdl:binding name="XxxxxxSvc-Endpoint0Binding" type="tns:portType"> 

    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> 

    <wsdl:operation name="version"> 
     <soap:operation style="document" soapAction="http://soap.jrimer-amp64/"/> 
     <wsdl:input> 
      <soap:body use="literal" parts="parameters"/> 
     </wsdl:input> 
     <wsdl:output> 
      <soap:body use="literal" parts="parameters"/> 
     </wsdl:output> 
    </wsdl:operation> 

    <wsdl:operation name="login"> 
     <soap:operation style="document" soapAction="http://soap.jrimer-amp64/"/> 
     <wsdl:input> 
      <soap:body use="literal" parts="parameters"/> 
     </wsdl:input> 
     <wsdl:output> 
      <soap:body use="literal" parts="parameters"/> 
     </wsdl:output> 
    </wsdl:operation> 

    <wsdl:operation name="logout"> 
     <soap:operation style="document" soapAction="http://soap.jrimer-amp64/"/> 
     <wsdl:input> 
      <soap:body use="literal" parts="parameters"/> 
     </wsdl:input> 
     <wsdl:output> 
      <soap:body use="literal" parts="parameters"/> 
     </wsdl:output> 
    </wsdl:operation> 

</wsdl:binding> 


<wsdl:message name="versionRequest"> 
    <wsdl:part name="parameters" element="ns0:versionRequest"/> 
</wsdl:message> 


<wsdl:message name="versionResponse"> 
    <wsdl:part name="parameters" element="ns0:versionResponse"/> 
</wsdl:message> 

<wsdl:message name="loginRequest"> 
    <wsdl:part name="parameters" element="ns0:loginRequest"/> 
</wsdl:message> 


<wsdl:message name="loginResponse"> 
    <wsdl:part name="parameters" element="ns0:loginResponse"/> 
</wsdl:message> 

<wsdl:message name="logoutRequest"> 
    <wsdl:part name="parameters" element="ns0:logoutRequest"/> 
</wsdl:message> 

<wsdl:message name="logoutResponse"> 
    <wsdl:part name="parameters" element="ns0:logoutResponse"/> 
</wsdl:message> 

我的SOAP功能类如下(通过setClass包括在我SoapServer的()):

class WebSvcSoapFunctions 
{ 
    private $username = ''; // username provided by the client during login() request 
    private $password = ''; // password provided by the client during login() request 

    /** 
    * Handle a login request 
    * 
    * @param string $user - Client's Username 
    * @param string $pass - Client's Password 
    */ 
    public function login($user,$pass) 
    { 
     $this->username = $user; 
     $this->password = $pass; 

     // should check for validity here, but for testing, return true. 
     return 'Successful Login. Welcome, '.$user; 
    } 

    /** 
    * Logs the client out. 
    * 
    */ 
    public function logout() 
    { 
     $this->username = ''; 
     $this->password = ''; 
     $_SESSION = array(); 
     session_destroy(); 
     return 'Logged Out Successfully.'; 
    } 
     /** 
    * checks if the client has logged in successfully 
    * 
    * @return bool - true=logged in, false = unauthenticated 
    */ 
    private function isAuthenticated() 
    { 
     if (isset($this->username) && $this->username != '') 
     { 
      return true; 
     } 
     else 
     { 
      return false; 
     } 
    } 

    /** 
    * Returns the version of the SOAP Server to the requesting client 
    * 
    */ 
    public function version() 
    { 
     if ($this->isAuthenticated()) 
     { 
      return 'Affinegy Service v1.0.0'; 
     } 
     else 
     { 
      return 'NOT AUTHORIZED.'; 
     } 
    } 
} 

我的SOAP客户端测试类如下:“未授权”

ini_set("soap.wsdl_cache_enabled", "0"); 
define('WSDL_URL','http://soap.jrimer-amp64/?wsdl'); 
try 
{ 
    $client = new SoapClient(WSDL_URL, array('trace'=>true)); 

    $request = 'version'; 
    $args = array(); 
    $SOAPResult = $client->$request($args); // call the SOAP Server's "version" function 
    OutputLastRequestResponse($client, $request, $args, $SOAPResult); 

    $request = 'login'; 
    $args['username'] = 'testuser'; 
    $args['password'] = '1234'; 
    $SOAPResult = $client->$request($args); // call the SOAP Server's "login" function 
    OutputLastRequestResponse($client, $request, $args, $SOAPResult); 

    $request = 'version'; 
    $args = array(); 
    $SOAPResult = $client->$request($args); // call the SOAP Server's "version" function 
    OutputLastRequestResponse($client, $request, $args, $SOAPResult); 

    $request = 'logout'; 
    $args = array(); 
    $SOAPResult = $client->$request($args); // call the SOAP Server's "logout" function 
    OutputLastRequestResponse($client, $request, $args, $SOAPResult); 

    $request = 'version'; 
    $SOAPResult = $client->$request($args); // call the SOAP Server's "version" function 
    OutputLastRequestResponse($client, $request, $args, $SOAPResult); 

} 
catch (Exception $e) 
{ 
    echo '<pre>FAILED: '.print_r($e,1).'</pre>'; // dump the client exception to screen 

    OutputLastRequestResponse($client); 
} 

/** 
* Displays the request and response of the test service call 
* 
* @param SoapServer $client - Object of type SoapClient that does the request 
* @param string $requested - name of the SOAP function called 
* @param array $args - Arguments sent to the SOAP function 
* @param string $returned - PHP readable value returned by the client calling the provided SOAP function 
*/ 
function OutputLastRequestResponse($client, $requested = '', $args=array(), $returned='') 
{ 
    echo '<h1>XXXXXXXX SERVICE SOAP SERVER TEST</h1>'; 
    echo 'Request: <pre>'.$requested.'</pre>'; 
    echo 'Request Arguments: <pre>'.print_r($args,1).'</pre>'; 
    echo 'Returned: <pre>'.$returned.'</pre>'; 
    echo 'Raw Request: <pre>'.htmlspecialchars($client->__getLastRequestHeaders()); 
    echo htmlspecialchars($client->__getLastRequest()).'</pre>'; 
    echo 'Raw Response: <pre>'.htmlspecialchars($client->__getLastResponseHeaders())."\n"; 
    echo htmlspecialchars($client->__getLastResponse()).'</pre>'; 
} 

从测试类运行的结果如下...注意是一切的反应,这表明只有WebSvcSoapFunctions ::版本()函数运行

XXXXXX服务SOAP服务器测试 请求:

版本

请求参数:

阵列()

返回:

未授权。

原始请求:

POST/HTTP/1.1主机: soap.jrimer-amp64连接: 保持活动的User-Agent:PHP-SOAP/5.2.10 内容类型:文本/ XML的;字符集= UTF-8 的SOAPAction: “HTTP://soap.jrimer-amp64/” 的Content-Length:227

原始响应:

HTTP/1.1 200 OK日期:星期四,16六月2011 19:43:32 GMT服务器:Apache/2.2.3 (CentOS)X-Powered-By:PHP/5.2。10 Set-Cookie: PHPSESSID = scbuin269990ahfargfq7k0972; path =/Expires:Thu,19 Nov 1981 08:52:00 GMT Cache-Control:no-store, no-cache,must-revalidate, post-check = 0,pre-check = 0 Pragma: no-cache Content-Length:209 Connection:close Content-Type: text/xml; charset = utf-8

NOT AUTHORIZED。

XXXXXX服务SOAP服务器测试 请求:

登录

请求参数:

阵列( [用户名] => jrimer [口令] => 1234)

返回的:

未授权。

原始请求:

POST/HTTP/1.1主机: soap.jrimer-amp64连接: 保持活动的User-Agent:PHP-SOAP/5.2.10 内容类型:文本/ XML的; charset = utf-8 SOAPAction: “http://soap.jrimer-amp64/” 内容长度:298 Cookie: PHPSESSID = scbuin269990ahfargfq7k0972;

usernamejrimerpassword1234

原始响应:

HTTP/1.1 200 OK日期:星期四,2011年6月16日 十九时43分32秒GMT服务器:Apache/2.2.3 (CentOS的)X-供电-By:PHP/5.2.10 Expires:Thu,19 Nov 1981 08:52:00 GMT Cache-Control:no-store,no-cache, 必须重新验证,post-check = 0, 预检查= 0 Pragma:no-cache Content-Length:209 Connection:close Content-Type:text/xml; charset = utf-8

NOT AUTHORIZED。

XXXXXX服务SOAP服务器测试 请求:

版本

请求参数:

阵列()

返回:

未经授权。

原始请求:

POST/HTTP/1.1主机: soap.jrimer-amp64连接: 保持活动的User-Agent:PHP的SOAP/5.2。10 Content-Type:text/xml; charset = utf-8 SOAPAction: “http://soap.jrimer-amp64/” 内容长度:227 Cookie: PHPSESSID = scbuin269990ahfargfq7k0972;

原始响应:

HTTP/1.1 200 OK日期:星期四,2011年6月16日19时43分32秒 GMT服务器:Apache/2.2.3 (CentOS的)X-Powered-通过:PHP/5.2.10 到期时间:星期四,1981年11月19日08:52:00 GMT 缓存控制:无存储,无缓存, 必须重新验证,后检查= 0, 预检查= 0 Pragma:no-cache Content-Length:209 Connection:close Content-Type:text/xml; charset = utf-8

NOT AUTHORIZED。

XXXXXX服务SOAP服务器测试 请求:

注销

请求参数:

阵列()

返回:

未经授权。

原始请求:

POST/HTTP/1.1主机: soap.jrimer-amp64连接: 保持活动的User-Agent:PHP-SOAP/5.2.10 内容类型:文本/ XML的; charset = utf-8 SOAPAction: “http://soap.jrimer-amp64/” 内容长度:227 Cookie: PHPSESSID = scbuin269990ahfargfq7k0972;

原始响应:

HTTP/1.1 200 OK日期:星期四,2011年6月16日19时43分32秒 GMT服务器:Apache/2.2.3 (CentOS的)X-Powered-通过:PHP/5.2.10 到期时间:星期四,1981年11月19日08:52:00 GMT 缓存控制:无存储,无缓存, 必须重新验证,后检查= 0, 预检查= 0 Pragma:no-cache Content-Length:209 Connection:close Content-Type:text/xml; charset = utf-8

NOT AUTHORIZED。

XXXXXX服务SOAP服务器测试 请求:

版本

请求参数:

阵列()

返回:

未经授权。

原始请求:

POST/HTTP/1.1主机: soap.jrimer-amp64连接: 保持活动的User-Agent:PHP-SOAP/5.2.10 内容类型:文本/ XML的; charset = utf-8 SOAPAction: “http://soap.jrimer-amp64/” 内容长度:227 Cookie: PHPSESSID = scbuin269990ahfargfq7k0972;

原始响应:

HTTP/1.1 200 OK日期:星期四,2011年6月16日19时43分32秒 GMT服务器:Apache/2.2.3 (CentOS的)X-Powered-通过:PHP/5.2.10 到期时间:星期四,1981年11月19日08:52:00 GMT 缓存控制:无存储,无缓存, 必须重新验证,后检查= 0, 预检查= 0 Pragma:no-cache Content-Length:209 Connection:close Content-Type:text/xml; charset = utf-8

NOT AUTHORIZED。

任何想法发生了什么?

注意:如果我简单地在WSDL中为VERSION函数注释掉下一个已定义函数变成“始终调用”函数(登录)的定义,那么我该在WSDL中配置什么错误?

回答

0

呀,它是在WSDL,我完全有它misdefined ...重组​​的WSDL,它现在正确域的请求......

+0

我有同样的问题,你可以告诉你做修复它是什么, 谢谢 – 2016-06-23 15:57:54

相关问题