0

私の C# サンプル クライアント ASP.NET プログラムは、Axis2 サーバーで呼び出しを正常に実行しますが、クライアントは応答を好まないようです。

私は得る:

クライアントは、'multipart/related;' の応答コンテンツ タイプを見つけました。境界 = MIMEBoundaryurn_uuid_38D413ACFC9D56F28E1258666845186; type="application/xop+xml"; start="<0.urn:uuid:38D413ACFC9D56F28E1258666845187@apache.org>"; start-info="text/xml"' ですが、'text/xml' が必要です。

MSDN フォーラムによると、MTOM を有効にする必要があると思われますが、現在は廃止された WSE 3 パッケージについてのみ説明しています。

WCF スペースでは、C# の ASP.NET プログラムの場合、MTOM を有効にする方法、またはこの応答のコンテンツ タイプの不一致を修正する方法を教えてください。実は、次に MTOM が必要になります。

4

2 に答える 2

2

まず、Axis2 でも MTOM を有効にする必要があります。axis2.xml 構成ファイル (WEB-INF/conf/axis2.xml) を見つけて、次の設定を調整します。

<axisconfig name="AxisJava2.0">
    <!-- ================================================= -->
    <!-- Parameters -->
    <!-- ================================================= -->
    .../...
    <parameter name="enableMTOM">true</parameter>
    .../...
</axisconfig>

これがないと、Axis は MTOM をまったく処理できず、クライアントは非常に混乱します。

XOP/MTOM への切り替えは multipart-mime への切り替えも意味し、クライアントは実際に multipart-mime の回答を得たので、結局のところ Axis2 設定は問題ないと思います :) クライアントがプレーンな XML (つまり、素敵な SOAP) を期待しているという事実response) は、クライアント側で MTOM をセットアップしていないことを示します。

BasicHttpBinding を使用していると仮定すると、WCF で MTOM を有効にするには、次のようにします。

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="MySOAP11Binding" 
                         ... 
                         messageEncoding="Mtom"
                         ...
                >
                .../...
                </binding>
            </basicHttpBinding>
            .../...

バインディング要素の maxBufferSize、maxBufferPoolSize、および maxReceivedMessageSize 属性も微調整する必要があります。

または、コードでこれを設定できます。

private ServiceProxy<MyPortTypeClient, MyPortType> getClient()
{
    EndpointAddress endpoint = new EndpointAddress("http://server/axis/services/My");

    // The binding
    BasicHttpBinding binding = new BasicHttpBinding();
    binding.OpenTimeout = minutes(1);
    binding.CloseTimeout = minutes(1);
    binding.SendTimeout = minutes(10);
    binding.ReceiveTimeout = minutes(10);

    binding.MaxBufferPoolSize = Int32.MaxValue;
    binding.MaxReceivedMessageSize = Int32.MaxValue;
    binding.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;

    binding.MessageEncoding = WSMessageEncoding.Mtom;
    if (binding is BasicHttpBinding)
    {
        // Also setting to streamed mode
        ((BasicHttpBinding)(Object)binding).TransferMode = TransferMode.Streamed;
    }

    binding.AllowCookies = true;

    // MyPortType and MyPortTypeClient are implemented in Reference.cs, i.e. this
    // code is generated by svcutil or Visual Studio from your WSDL.
    MyPortTypeClient _proxy = new MyPortTypeClient(binding, endpoint);
    ServiceProxy<MyPortTypeClient, MyPortType> proxy = new ServiceProxy<MyPortTypeClient, MyPortType>(_proxy);

    if (!String.IsNullOrEmpty(wsUsername) && !String.IsNullOrEmpty(wsPassword))
    {
        UserNamePasswordClientCredential credentials = _proxy.ClientCredentials.UserName;
        credentials.UserName = wsUsername;
        credentials.Password = wsPassword;
    }
    return proxy;
}

コードでこれを行うことの良い点は、特定のバインディングに設定できるパラメーターに関して、IDE からヘルプが得られることです。BasicHttpBinding からたとえば WSHttpBinding に切り替えると、新しいバインディングと一致しないパラメーターに対してコンパイル エラーが発生します。

于 2010-11-17T20:31:49.810 に答える
0

これは通常、クライアントが xml 応答を期待しているのに、サーバーから解析できないというエラー メッセージを受け取るということです。

応答をログに記録するか、ネットワーク スニファー (フィドラー) を使用して、何が返されているかを確認してください。

于 2009-11-21T11:12:04.410 に答える