Axis2 Web 服务的 C# 客户端抱怨“但需要‘text/xml’”

发布于 2024-08-12 01:57:30 字数 608 浏览 5 评论 0原文

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

我得到:

客户端发现响应内容类型为“多部分/相关;” 边界=MIMEBoundaryurn_uuid_38D413ACFC9D56F28E1258666845186; 类型=“应用程序/xop+xml”; start="<0.urn:uuid:[电子邮件受保护]> ;”; start-info="text/xml"',但预期为“text/xml”。

根据 MSDN 论坛,我应该必须启用 MTOM,但他们仅针对现已过时的 WSE 3 软件包解释这一点。

在 WCF 空间中,对于 C# 中的 ASP.NET 程序,如何启用 MTOM 或以其他方式修复此响应内容类型不匹配?事实上,接下来我需要 MTOM。

My C# sample client ASP.NET program successfully runs a call in my Axis2 server but the client does not seem to like the response.

I get:

Client found response content type of 'multipart/related;
boundary=MIMEBoundaryurn_uuid_38D413ACFC9D56F28E1258666845186;
type="application/xop+xml";
start="<0.urn:uuid:[email protected]>";
start-info="text/xml"', but expected 'text/xml'.

According to the MSDN forums I supposedly must enable MTOM but they only explain this for the now-obsolete WSE 3 package.

In the WCF space, for an ASP.NET program in C#, how to I enable MTOM or otherwise fix this response content-type mismatch? Actually, I'll need MTOM next.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愁以何悠 2024-08-19 01:57:31

一方面,您还必须在 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)响应)表明您尚未在客户端设置 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,您将收到那些与新绑定不匹配的参数的编译错误。

For one thing, you have to enable MTOM in Axis2 as well. Find your axis2.xml configuration file (WEB-INF/conf/axis2.xml) and adjust the following setting:

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

Wihthout this, Axis will not handle MTOM at all and the client will be very confused.

Switching to XOP/MTOM means switching to multipart-mime as well, and your client actually got a multipart-mime answer, so I suppose the Axis2 setting is OK afterall :) The fact that your client is expecting plain XML (i.e. a nice SOAP response) indicates that you have not set up MTOM on the client side.

Supposing you are using a BasicHttpBinding, enabling MTOM in WCF could be done as:

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

You will most certainly have to tweak the maxBufferSize, maxBufferPoolSize and maxReceivedMessageSize attributes of the binding element as well.

Alternatively, you can set this up in code:

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;
}

The nice thing about doing this in code, is that you will get help form your IDE regarding what parameters can be set for any specific binding. If you switch from BasicHttpBinding to, say, WSHttpBinding you will get compilation errors for those parameters that does not match the new binding.

无声情话 2024-08-19 01:57:31

通常,客户端期望 xml 响应,但从服务器收到一条无法解析的错误消息。

记录响应或使用网络嗅探器(fiddler)来检查您返回的内容。

This in normally that the client expects an xml response, but gets an error message from the server that it cannot parse.

Either log the reponse or use a network sniffer (fiddler) to check what you are getting back.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文