2

wsdl.exe我通过-URL创建了一个 C# 代理类WSDL。我在我无法控制的 Web 应用程序的上下文中使用此代理类(因此无法更改 aweb.conf或类似内容)。我也无法更改正在与之交谈的 Web 服务中的任何内容。

调用 Web 服务时,我收到以下异常:

Client found response content type of 'multipart/related; type="application/xop+xml"; 
boundary="uuid:5c314128-0dc0-4cad-9b1a-dc4a3e5917bb"; start="<root.message@cxf.apache.org>"; 
start-info="application/soap+xml"', but expected 'application/soap+xml'.

根据我的阅读,这是Web 服务使用MTOM的问题。现在我试图告诉我的班级接受 MTOM,但我发现的只是web.conf.

代理类派生自SoapHttpClientProtocol并且看起来像这样(相关部分):

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]    
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name = "myrequestSoapBinding", Namespace = "http://namespace.of.company.of.webservice/")]
public class myrequest : System.Web.Services.Protocols.SoapHttpClientProtocol
{
    public myrequest(string url)
    {
        this.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap12;            
        this.Url = url;
    }

    [return: System.Xml.Serialization.XmlElementAttribute("return", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, DataType = "base64Binary")]
    public byte[] getDocuments([System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, DataType = "base64Binary")] byte[] input)
    {
        try
        {
            object[] results = this.Invoke("getDocuments", new object[] {
                input});
            return ((byte[])(results[0]));
        }
        catch (Exception ex)
        {
            var realResponse = StripResponse(ex.Message);
            return Encoding.UTF8.GetBytes(realResponse.ToString());
        }
    }
}

try ... catchin是一个 hacky 解决方法,可以从getDocuments异常中获取“真正的”服务响应Message——这并不是我真正想要实现的方式。

所以我的问题是:有没有办法改变代理类中的绑定来接受MTOM响应?

4

1 回答 1

2

从我所做的少量研究来看,如果您确实可以访问网络配置(我知道您没有)并且您打开了 MTOM,那么 Visual Studio 将生成两个代理类:

  1. 一种从SoapHttpClientProtocol派生的标准,并且;
  2. 带有“Wse”的 WSE 附加到派生自Microsoft.Web.Services3.WebServicesClientProtocol的类名

能够接受 MTOM 的是 WebServicesClientProtocol 实现。要让 WSDL 创建派生自 WebServicesClientProtocol 的代理,请遵循此 MSDN 文章顶部的注释。

希望这将解决问题。

于 2015-02-13T18:01:54.110 回答