2

-URLwsdl.exeから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 ... catchingetDocumentsは、例外から「実際の」サービス応答を取得するハックな回避策です。Messageこれは、私がこれを実装したい方法ではありません。

だから私の質問は:MTOM応答を受け入れるようにプロキシ クラスのバインディングを変更する方法はありますか?

4

1 に答える 1

2

支援するために私が行った少量の調査から、Web 構成にアクセスでき (アクセスできないことはわかってます)、MTOM をオンにすると、Visual Studio は2 つのプロキシ クラスを生成するようです。 :

  1. SoapHttpClientProtocolから派生した標準的なもの、および;
  2. Microsoft.Web.Services3.WebServicesClientProtocolから派生したクラス名に「Wse」が追加された WSE のもの

MTOM を受け入れることができるのは WebServicesClientProtocol 実装です。WSDL で WebServicesClientProtocol から派生するプロキシを作成するには、この MSDN 記事の上部にある注に従ってください。

これで問題が解決することを願っています。

于 2015-02-13T18:01:54.110 に答える