SOAP请求参数不会到达PHP函数

时间:2013-06-24 16:26:57

标签: php web-services soap parameters wsdl


我正在使用WSDL支持SOAP Web服务 WSDL文件位于:http://paygoo.com/soap/server.wsdl

我的Webservice中有3个函数。 GetUserInfo,TransferFromWallet和TransferToWallet。

函数GetUserInfo工作正常,所以我设计了另外两个这样的函数,但另外两个函数TransferFromWallet和TransferToWallet不会从客户端重新获取参数。

函数GetUserInfo如下所示:

function GetUserInfo($sessionID)
{
if (mysql_num_rows($result)==1){
        if (mysql_num_rows($result)==1)
        {
            $element->balance = new SoapVar($balance, XSD_DECIMAL, '','','');
            $element->currencyCode = new SoapVar("EUR", XSD_STRING, '','','');
            $element->displayName = new SoapVar($row['username'], XSD_STRING, '','','');
            $element->languageCode = new SoapVar("DE", XSD_STRING, '','','');
            $element->UID = new SoapVar($row['ID'], XSD_STRING, '','','');
            $element->responseCode = new SoapVar("OK", XSD_STRING, '','','');
            return new SoapVar($element, SOAP_ENC_OBJECT,'');
        }else
        {
            $element->responseCode = new SoapVar("UNEXPECTED_ERROR", XSD_STRING, '','','');
            return new SoapVar($element, SOAP_ENC_OBJECT,'');
        }
    }else
    {
        $element->responseCode = new SoapVar("INVALID_SESSION", XSD_STRING, '','','');
        return new SoapVar($element, SOAP_ENC_OBJECT,'');
    }
}

TransferFromWallet和TransferToWallet函数如下所示:

    function TransferFromWallet($sessionID, $UID, $amount)
{
        if (mysql_num_rows($result)==1){
            if ($row2['ID'] == $UID)
            {
                if($amount > 0 and $amount <= $balance)
                {
                    $element->responseCode = new SoapVar("OK", XSD_STRING, '','','');
                    return new SoapVar($element, SOAP_ENC_OBJECT,'');
                }else
                {
                    $element->responseCode = new SoapVar("BALANCE_TOO_LOW", XSD_STRING, '','','');
                    return new SoapVar($element, SOAP_ENC_OBJECT,'');
                }
            }else
            {
                $element->responseCode = new SoapVar("INVALID_UID", XSD_STRING, '','','');
                return new SoapVar($element, SOAP_ENC_OBJECT,'');
            }
        }else
        {
            $element->responseCode = new SoapVar("INVALID_SESSION", XSD_STRING, '','','');
            return new SoapVar($element, SOAP_ENC_OBJECT,'');
        }
}

我定义了所有功能和服务器,如下所示:

$server = new SoapServer("./soap/server.wsdl", 
array('uri' => "http://paygoo.com/server.php"));
//Funktionen zum SOAP Server hinzufügen
$server->addFunction('GetUserInfo');
$server->addFunction('TransferFromWallet');
$server->addFunction('TransferToWallet');
//Hier wird die Abfrage abgearbeitet
$server->handle();

我的测试客户端看起来像这样:

    <?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set("soap.wsdl_cache_enabled", 0);
$requesttype = $_REQUEST['soapRequest']; //Art des Requests Variable wird gesetzt.
$sessionID = $_REQUEST['sessionID']; //session_id Variable wird gesetzt.
$UID = $_REQUEST['UID']; //UserID Variable wird gesetzt
$amount = $_REQUEST['balance']; //Zu transferierendes Guthaben Varialbe wird gesetzt
//$client = new SoapClient('http://paygoo.com/soap/server.wsdl');  //{url} wie immer ersetzen

//$sessionID = 'ae3a12e662884604c069b4dfc5a13afd';
$wsdl = 'http://paygoo.com/soap/server.wsdl';
$client = new SoapClient($wsdl);
if($requesttype=="GetUserInfo")
{
    //$parms = array('sessionID' => $sessionID);
    $result = $client->GetUserInfo($sessionID);
}
if($requesttype=="TransferFromWallet"){
//$parms = array('sessionID' => $sessionID, 'UID' => $UID, 'amount' => $amount);
$result = $client->TransferFromWallet($sessionID, $UID, $amount);
}

if($requesttype=="TransferToWallet"){
    //$parms = array('sessionID' => $sessionID, 'UID' => $UID, 'amount' => $amount);
    $result = $client->TransferToWallet($sessionID, $UID, $amount);
}
?>
<h1>Result</h1>
<pre> <?php var_dump($result) ?> </pre>

SOAP服务器不接收参数sessionID,UID和amount
编辑:
我现在在<types>标签中定义了参数。像这样:

<wsdl:types>
    <xsd:schema elementFormDefault='qualified' targetNamespace='http://paygoo.com/soap/server.wsdl'>
        <xsd:element name='transferRequest'>
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element minOccurs='0' maxOccurs='1' name='sessionID' type='xsd:string'/>
                    <xsd:element minOccurs='0' maxOccurs='1' name='UID' type='xsd:string'/>
                    <xsd:element minOccurs='0' maxOccurs='1' name='amount' type='xsd:decimal'/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
        <xsd:element name='transferResponse'>
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element minOccurs='0' maxOccurs='1' name='ResponseCode' type='xsd:string'/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    </xsd:schema>
</wsdl:types>

如果我发送此请求:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:xmethodsWallet">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:TransferFromWallet soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <transferRequest>
      <sessionID>c230f895fb98ab9159f51fd0297e236d</sessionID>
      <UID>975</UID>
      <amount>1</amount>
      </transferRequest>
      </urn:TransferFromWallet>
   </soapenv:Body>
</soapenv:Envelope>

我的函数TransferFromWallet没有收到任何参数 如果我在客户端上运行__getFunctions__getTypes,我会收到以下回复:

Funktionen

 array(3) {
  [0]=>
  string(43) "string GetUserInfo(string $userinfoRequest)"
  [1]=>
  string(69) "transferResponse TransferFromWallet(transferRequest $transferRequest)"
  [2]=>
  string(67) "transferResponse TransferToWallet(transferRequest $transferRequest)"
}

Typen

 array(2) {
  [0]=>
  string(75) "struct transferRequest {
 string sessionID;
 string UID;
 decimal amount;
}"
  [1]=>
  string(49) "struct transferResponse {
 string ResponseCode;
}"
}

任何人都可以告诉我为什么我不回复函数中的参数?

2 个答案:

答案 0 :(得分:0)

在WSDL中,将输入参数定义为complexType:

<message name='TransferFromWalletRequest'>
    <part name="parameters">
        <complexType>
            <sequence>
                <element name='sessionID' type='xsd:string'/>
                <element name='UID' type='xsd:string'/>
                <element name='amount' type='xsd:decimal'/>
            </sequence>
        </complexType>
    </part>
</message>

TransferToWallet执行相同操作。即使GetUserInfo只接受一个参数,你应该给它与上面相同的处理,因为你实际上没有得到一个命名参数,它只是取第一个参数。

答案 1 :(得分:0)

我找到了解决问题的方法:
SOAP服务将对象传输到我的服务器 我不得不这样读这个对象:

function TransferFromWallet($transferRequest)
{
        $sessionID= $transferRequest->sessionID;
        $UID = $transferRequest->UID;
        $amount = $transferRequest->amount;
                .
                .
                .
}