0

私のSOAPサーバーは、ログイン、ログアウト、バージョンの3つの操作でセットアップされています。

ログイン関数のコードは現在、ユーザー名とパスワードの2つのパラメーターを受け入れ、関数クラスのプライベートユーザー名とパスワードの変数に保存することで自動的に「認証」し、現在「偽造」しています。Webサービスアクションのエントリポイントでセッションを開始しました。初期化中にSoapServerで関数クラスを設定すると、次のように接続が保持されます。

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

SOAP CLIENTを作成してサービスを呼び出すと、呼び出される関数に関係なく、呼び出された関数ではなく、version()関数が常に実行されているように見えます。これはおそらく私のWSDLの記述方法によるものだと思いますが、問題はわかりません(私は新しいです)...

PHPSoapServerを介して次のWSDLをリッスンしています。

<?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.';
        }
    }   
}

私のSOAPCLIENTテストクラスは次のとおりです。

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 :: version()関数のみが実行されていることを示します

Xxxxxx SERVICE SOAP SERVER TESTリクエスト:

バージョン

引数の要求:

配列 ( )

戻ってきた:

許可されていません。

生のリクエスト:

POST / HTTP / 1.1ホスト:soap.jrimer-amp64接続:Keep-Aliveユーザーエージェント:PHP-SOAP / 5.2.10コンテンツタイプ:text / xml; charset = utf-8 SOAPAction: "http://soap.jrimer-amp64/" Content-Length:227

生の応答:

HTTP / 1.1 200 OK日付:2011年6月16日木曜日19:43:32 GMTサーバー:Apache / 2.2.3(CentOS)X-Powered-By:PHP / 5.2.10 Set-Cookie:PHPSESSID = scbuin269990ahfargfq7k0972; path = /有効期限:1981年11月19日木曜日08:52:00 GMTキャッシュ制御:no-store、no-cache、must-revalidate、post-check = 0、pre-check = 0プラグマ:no-cache Content-長さ:209接続:閉じるContent-Type:text / xml; charset = utf-8

許可されていません。

Xxxxxx SERVICE SOAP SERVER TESTリクエスト:

ログインする

引数の要求:

配列([ユーザー名] =>jrimer[パスワード]=>1234)

戻ってきた:

許可されていません。

生のリクエスト:

POST / HTTP / 1.1ホスト:soap.jrimer-amp64接続:Keep-Aliveユーザーエージェント:PHP-SOAP / 5.2.10コンテンツタイプ:text / xml; charset = utf-8 SOAPAction: "http://soap.jrimer-amp64/" Content-Length:298 Cookie:PHPSESSID = scbuin269990ahfargfq7k0972;

usernamejrimerpassword1234

生の応答:

HTTP / 1.1 200 OK日付:2011年6月16日木曜日19:43:32 GMTサーバー:Apache / 2.2.3(CentOS)X-Powered-By:PHP / 5.2.10有効期限:1981年11月19日木曜日08:52: 00 GMT Cache-Control:no-store、no-cache、must-revalidate、post-check = 0、pre-check = 0プラグマ:no-cache Content-Length:209接続:close Content-Type:text / xml; charset = utf-8

許可されていません。

Xxxxxx SERVICE SOAP SERVER TESTリクエスト:

バージョン

引数の要求:

配列 ( )

戻ってきた:

許可されていません。

生のリクエスト:

POST / HTTP / 1.1ホスト:soap.jrimer-amp64接続:Keep-Aliveユーザーエージェント:PHP-SOAP / 5.2.10コンテンツタイプ:text / xml; charset = utf-8 SOAPAction: "http://soap.jrimer-amp64/" Content-Length:227 Cookie:PHPSESSID = scbuin269990ahfargfq7k0972;

生の応答:

HTTP / 1.1 200 OK日付:2011年6月16日木曜日19:43:32 GMTサーバー:Apache / 2.2.3(CentOS)X-Powered-By:PHP / 5.2.10有効期限:1981年11月19日木曜日08:52: 00 GMT Cache-Control:no-store、no-cache、must-revalidate、post-check = 0、pre-check = 0プラグマ:no-cache Content-Length:209接続:close Content-Type:text / xml; charset = utf-8

許可されていません。

Xxxxxx SERVICE SOAP SERVER TESTリクエスト:

ログアウト

引数の要求:

配列 ( )

戻ってきた:

許可されていません。

生のリクエスト:

POST / HTTP / 1.1ホスト:soap.jrimer-amp64接続:Keep-Aliveユーザーエージェント:PHP-SOAP / 5.2.10コンテンツタイプ:text / xml; charset = utf-8 SOAPAction: "http://soap.jrimer-amp64/" Content-Length:227 Cookie:PHPSESSID = scbuin269990ahfargfq7k0972;

生の応答:

HTTP / 1.1 200 OK日付:2011年6月16日木曜日19:43:32 GMTサーバー:Apache / 2.2.3(CentOS)X-Powered-By:PHP / 5.2.10有効期限:1981年11月19日木曜日08:52: 00 GMT Cache-Control:no-store、no-cache、must-revalidate、post-check = 0、pre-check = 0プラグマ:no-cache Content-Length:209接続:close Content-Type:text / xml; charset = utf-8

許可されていません。

Xxxxxx SERVICE SOAP SERVER TESTリクエスト:

バージョン

引数の要求:

配列 ( )

戻ってきた:

許可されていません。

生のリクエスト:

POST / HTTP / 1.1ホスト:soap.jrimer-amp64接続:Keep-Aliveユーザーエージェント:PHP-SOAP / 5.2.10コンテンツタイプ:text / xml; charset = utf-8 SOAPAction: "http://soap.jrimer-amp64/" Content-Length:227 Cookie:PHPSESSID = scbuin269990ahfargfq7k0972;

生の応答:

HTTP / 1.1 200 OK日付:2011年6月16日木曜日19:43:32 GMTサーバー:Apache / 2.2.3(CentOS)X-Powered-By:PHP / 5.2.10有効期限:1981年11月19日木曜日08:52: 00 GMT Cache-Control:no-store、no-cache、must-revalidate、post-check = 0、pre-check = 0プラグマ:no-cache Content-Length:209接続:close Content-Type:text / xml; charset = utf-8

許可されていません。

何が起こっているのかアイデアはありますか?

注:VERSION関数のWSDLの定義をコメントアウトするだけで、次に定義される関数が「常に呼び出される」関数(ログイン)になることに気付きました...そのWSDLで何が間違って構成されていますか?

4

1 に答える 1

0

ええ、それは WSDL でした。完全に間違って定義されています... WSDL を再構築し、リクエストを正しくフィールドするようになりました...

于 2011-06-17T18:22:30.620 に答える