0

我的 C# 示例客户端 ASP.NET 程序在我的 Axis2 服务器中成功运行了一个调用,但客户端似乎不喜欢响应。

我得到:

客户端发现响应内容类型为“多部分/相关”;边界=MIMEBoundaryurn_uuid_38D413ACFC9D56F28E1258666845186;类型=“应用程序/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 回答