3

Visual Studio 2010 から生成された Web サービス プロキシ クラスを使用して、.net 2.0 クライアントから Web サービスにアクセスします。

これはすべて正常に機能しますが、私の問題は、Web サービスにテストシステム用の wsdl と本番システム用の wsdl があることです。

Web サービスは構造的に完全に同一ですが、それらの xml 名前空間は異なります。

私のコードでは、Web サービスのサービス URL を設定でき、通信は機能します (TraceExtension を使用して SOAP メッセージをログ ファイルにダンプします) が、逆シリアル化になると例外が発生します。

これは、テスト システムの WSDL ファイルを使用してプロキシ クラスを生成し、次のようないくつかの属性を追加したためだと思います: [System.Xml.Serialization.SoapTypeAttribute(Namespace="testservice url here")]

もちろん、プロジェクトをコピーして実稼働サービスへの Web 参照を追加することもできますが、これによりコードが複製され、将来 2 つのプロジェクトでさらに変更を加える必要があり、もちろんエラーが発生しやすくなります。

以下は、テスト システム サービスに対して Login-method を呼び出すための有効な応答です。

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://TEST_SERVER_NAME/ProjectService">
    <SOAP-ENV:Body>
        <ns1:loginResponse xmlns:ns1="http://TEST_SERVER_NAME/ProjectService">
            <login_result xsi:type="tns:LoginResult">
                <errorcode xsi:type="xsd:integer">0</errorcode>
                <errortext xsi:type="xsd:string">Successfully logged in</errortext>
                <logincode xsi:type="xsd:string">wF3N5vdPsueL0aYlp41i6B8VTZEJztqx</logincode>
            </login_result>
        </ns1:loginResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

本番 Web サービスからの同じ応答を次に示します。

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://PRODUCTION_SERVER_NAME/ProjectService">
    <SOAP-ENV:Body>
        <ns1:loginResponse xmlns:ns1="http://TEST_SERVER_NAME/ProjectService">
            <login_result xsi:type="tns:LoginResult">
                <errorcode xsi:type="xsd:integer">0</errorcode>
                <errortext xsi:type="xsd:string">Successfully logged in</errortext>
                <logincode xsi:type="xsd:string">wOmdlZMkIXVL4H8uTGU69hgpNsK1Cz3Q</logincode>
            </login_result>
        </ns1:loginResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

ご覧のとおり、2 つの応答は xmlns:tns 属性のみが異なりますが、xmlns:ns1 属性は常に異なりますhttp://TEST_SERVER_NAME/ProjectService(これは、テスト システムの WSDL を使用して生成されたプロキシ クラスから来ていると思います)。logincode は単なる認証トークンであり、常に異なるため、問題ありません。

この問題に対する他の解決策はありますか?

4

1 に答える 1

1

パーティーに遅れましたが、この問題を解決するためにプリプロセッサ ディレクティブを使用します。

#define SANDBOX //Change from sandbox to production to switch between both systems.

#if SANDBOX
    using NetSuite.com.netsuite.sandbox.webservices;
#endif

#if PRODUCTION
    using NetSuite.com.netsuite.webservices;
#endif

両方の参照が Web 参照としてプロジェクトに追加されていることを確認し、運用 Webサービスを使用するため、およびSANDBOXサンドボックス用に変更します。PRODUCTIONSANDBOX

これはおそらく最もエレガントなソリューションではありませんが、迅速で汚れていて、私が必要としているものを正確に実行します.

于 2013-12-19T16:29:12.810 に答える