簡體   English   中英

Axis2 Web服務的C#客戶端抱怨“但預期為'text / xml'”

[英]C# client of Axis2 web service complains “but expected 'text/xml'”

我的C#示例客戶端ASP.NET程序在Axis2服務器中成功運行了調用,但是客戶端似乎不喜歡響應。

我得到:

客戶發現響應內容類型為“多部分/相關”; 邊界= MIMEBoundaryurn_uuid_38D413ACFC9D56F28E1258666845186; 類型= “應​​用/ XOP + xml” 的; 開始= “<0.urn:UUID:38D413ACFC9D56F28E1258666845187@apache.org>”; start-info =“ text / xml”“,但應為'text / xml'。

根據MSDN論壇,我應該必須啟用MTOM,但它們僅針對現已過時的WSE 3軟件包進行了解釋。

在WCF空間中,對於C#中的ASP.NET程序,如何啟用MTOM或以其他方式解決此響應內容類型不匹配的問題? 實際上,接下來我需要MTOM。

一方面,您還必須在Axis2中啟用MTOM。 找到您的axis2.xml配置文件(WEB-INF / conf / axis2.xml)並調整以下設置:

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

除此之外,Axis根本不會處理MTOM,並且客戶會非常困惑。

切換到XOP / MTOM也意味着也要切換到multi-mime,並且您的客戶端實際上得到了multi-mime的答案,所以我想畢竟Axis2設置是可以的:)您的客戶端期望使用純XML(即不錯的SOAP)這一事實響應)表示您尚未在客戶端上設置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,則將得到與新綁定不匹配的那些參數的編譯錯誤。

通常,這是指客戶端期望xml響應,但是從服務器獲取了無法解析的錯誤消息。

記錄響應或使用網絡嗅探器(提琴手)檢查返回的內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM