我通过C# -URL通过wsdl.exe创建了一个WSDL代理类。我在一个web应用程序的上下文中使用这个代理类,而我并不控制这个应用程序(因此无法更改web.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 ... catch in getDocuments是一个麻烦的解决方案,它从异常Message获得“真正的”服务响应--这并不是我真正想要实现的方式。
因此,我的问题是:是否有一种方法可以更改代理类中的绑定以接受MTOM响应?
发布于 2015-02-13 18:01:54
从我为帮助您所做的少量研究来看,如果您确实访问了web配置(我知道您没有),并且打开了MTOM,那么Visual将生成两个代理类:
能够接受MTOM的是WebServicesClientProtocol实现。要让WSDL创建一个从WebServicesClientProtocol派生的代理,请按照本MSDN文章的顶部上的备注操作。
希望这能解决这个问题。
https://stackoverflow.com/questions/27403344
复制相似问题