41

会社が購入した製品のWebサービスを利用するときに、奇妙な問題が発生します。この製品はキャンペーンコマンダーと呼ばれ、Eメールビジョンと呼ばれる会社によって作られています。「DataMassUpdateSOAPAPI」を使おうとしています。

Webサービスのいずれかのメソッドを呼び出そうとすると、呼び出しは実際には成功しますが、応答の処理時にクライアントが失敗し、例外が発生します。

エラーの詳細は以下のとおりです。皆さんが提供できる支援に感謝します。

Webリファレンス(古いスタイルのWebサービスクライアント)の使用中にエラーが発生しました

サービスをWeb参照として使用するInvalidOperationExceptionと、呼び出しを行うと、次のメッセージが表示されます。

Client found response content type of 'multipart/related; type="application/xop+xml"; boundary="uuid:170e63fa-183c-4b18-9364-c62ca545a6e0"; start="<root.message@cxf.apache.org>"; start-info="text/xml"', but expected 'text/xml'.
The request failed with the error message:
--

--uuid:170e63fa-183c-4b18-9364-c62ca545a6e0
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ns2:openApiConnectionResponse xmlns:ns2="http://api.service.apibatchmember.emailvision.com/" xmlns:ns3="http://exceptions.service.apibatchmember.emailvision.com/">
      <return>DpKTe-9swUeOsxhHH9t-uLPeLyg-aa2xk3-aKe9oJ5S9Yymrnuf1FxYnzpaFojsQSkSCbJsZmrZ_d3v2-7Hj</return>
    </ns2:openApiConnectionResponse>
  </soap:Body>
</soap:Envelope>
--uuid:170e63fa-183c-4b18-9364-c62ca545a6e0--
--.

ご覧のとおり、応答soapエンベロープは有効に見えます(これは有効な応答であり、呼び出しは成功しました)が、クライアントはコンテンツタイプに問題があるようで、例外を生成します。

サービスリファレンス(WCFクライアント)の使用中にエラーが発生しました

サービスをサービス参照として使用するProtocolExceptionと、呼び出しを行うと、次のメッセージが表示されます。

The content type multipart/related; type="application/xop+xml"; boundary="uuid:af66440a-012e-4444-8814-895c843de5ec"; start="<root.message@cxf.apache.org>"; start-info="text/xml" of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 648 bytes of the response were: '
--uuid:af66440a-012e-4444-8814-895c843de5ec
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ns2:openApiConnectionResponse xmlns:ns2="http://api.service.apibatchmember.emailvision.com/" xmlns:ns3="http://exceptions.service.apibatchmember.emailvision.com/">
      <return>Dqaqb-MJ9V_eplZ8fPh4tdHUbxM-ZtuZsDG6GalAGZSfSzyxgtuuIxZc3aSsnhI4b0SCbJsZmrZ_d3v2-7G8</return>
    </ns2:openApiConnectionResponse>
  </soap:Body>
</soap:Envelope>
--uuid:af66440a-012e-4444-8814-895c843de5ec--'.

前の例と同じように。有効なsoap応答があり、呼び出しは成功しましたが、クライアントはコンテンツタイプに問題があるようで、例外を生成しました。

クライアントが応答タイプに問題がないように設定できるオプションはありますか?私はいくつかのグーグル検索をしました、しかし私が見つけたものは今のところ私を助けませんでした。

4

7 に答える 7

89

同じ問題に苦しんでいる人のために; Webサービスをサービスリファレンス(WCF)として利用するためのソリューションを見つけました。BasicHttpBinding.MessageEncodingプロパティを「Mtom」に設定する必要があります。

必要な構成設定のスニペットは次のとおりです。

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

編集:カスタムバインディングで同じ問題が発生している場合は、@robmzdの回答を参照してください。

古いスタイルのWebリファレンスとして使用するための解決策はまだ見つかりません。

于 2012-05-08T11:01:24.230 に答える
15

数日間これに苦労した後、私はこの問題の非常に簡単な解決策を見つけました:

  1. VS2010のメインメニューから[ツール]->[WCFサービス構成エディター]を選択して、構成エディターをアクティブ化します。
  2. もう一度閉じます。
  3. App.Configファイルを右クリックして、新しいメニュー項目[WCF構成の編集]を見つけます。
  4. バインディングをクリックします。
  5. MessageEncodingをMtomに変更します。
  6. 保存する。

これが誰かに役立つことを願っています。

于 2014-06-26T16:06:21.553 に答える
7

私は同じ問題を抱えていましたが、<customBinding><mtomMessageEncoding>これを修正するには、バインディングの下にある別の構成ノードを使用してMtomメッセージエンコーディングを構成できます。

<configuration>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="MyServiceBinding">
          <mtomMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap12" writeEncoding="utf-8">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
          </mtomMessageEncoding>
        </binding>
      </customBinding>
    </bindings>
  </system.serviceModel>
</configuration>
于 2015-12-18T08:28:00.407 に答える
6

WCFサービスをセルフホスティングしていて、WCFクライアントでサービスを利用している場合。MessageEncoding次のように、ホストでプロパティを設定することを忘れないでください。

BasicHttpBinding binding = new BasicHttpBinding();
binding.MessageEncoding = WSMessageEncoding.Mtom;

私もこの問題に遭遇しました。クライアントは起動時にこの例外をスローし続けMessageEncodingましたが、ホストアプリケーションでバインディングプロパティを設定するのを忘れたことに気付くまで、その理由を理解できませんでした。

于 2013-05-24T13:56:18.837 に答える
5

私は同じ機能と同じ会社でまったく同じ問題を抱えており、正しい答えを見つけるためにGoogleで数時間を費やしています。何度も試してみて、ようやく手に入れました。これが私がしたことです:次の文字列は私を返すEメールビジョンから機能する応答でした(私の主な目的は大量アップロードでしたが、単純さとテストのためにgetLastUploadに交換します)。

文字列(2180) "

--uuid:5c8a8a1d-a29c-43d0-baaa-cb3a8c189962
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:getLastUploadResponse xmlns:ns2="http://api.service.apibatchmember.emailvision.com/" xmlns:ns3="http://exceptions.service.apibatchmember.emailvision.com/"><return><id>254816</id><source>API_BATCH_MEMBER</source><status>DONE</status></return><return><id>254810</id><source>API_BATCH_MEMBER</source><status>DONE</status></return><return><id>254805</id><source>API_BATCH_MEMBER</source><status>DONE</status></return><return><id>254799</id><source>API_BATCH_MEMBER</source><status>DONE</status></return><return><id>254797</id><source>API_BATCH_MEMBER</source><status>DONE</status></return><return><id>254791</id><source>API_BATCH_MEMBER</source><status>DONE</status></return><return><id>254790</id><source>API_BATCH_MEMBER</source><status>DONE</status></return><return><id>254771</id><source>API_BATCH_MEMBER</source><status>DONE</status></return><return><id>254770</id><source>API_BATCH_MEMBER</source><status>ERROR</status></return><return><id>254759</id><source>API_BATCH_MEMBER</source><status>DONE</status></return><return><id>254747</id><source>API_BATCH_MEMBER</source><status>DONE</status></return><return><id>253619</id><source>CCMD</source><status>DONE</status></return><return><id>238053</id><source>CCMD</source><status>DONE WITH ERROR(S)</status></return><return><id>216618</id><source>CCMD</source><status>DONE WITH ERROR(S)</status></return><return><id>200373</id><source>CCMD</source><status>DONE</status></return><return><id>200367</id><source>CCMD</source><status>DONE</status></return><return><id>195445</id><source>CCMD</source><status>DONE</status></return><return><id>194579</id><source>CCMD</source><status>DONE</status></return><return><id>194263</id><source>CCMD</source><status>DONE</status></return><return><id>193740</id><source>CCMD</source><status>DONE</status></return></ns2:getLastUploadResponse></soap:Body></soap:Envelope>
--uuid:5c8a8a1d-a29c-43d0-baaa-cb3a8c189962--

文字列の先頭を見ると、キー値と、SoapClientクラスが「XMLドキュメントを取得していないように見える」という例外をスローするようにしたサーバーの他のスタッフが含まれています。xmlドキュメントはこのすべてのスタッフの下にありましたが。

--uuid:5c8a8a1d-a29c-43d0-baaa-cb3a8c189962
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

同様に、文字列の下部(xmlの後)に同じキーが表示されます

--uuid:5c8a8a1d-a29c-43d0-baaa-cb3a8c189962--

したがって、解決策は、xmlファイルの最初から最初まで、およびxmlファイルの最後から文字列の最後まで文字列の一部を削除しようとすることでした。MTOMphpクライアントでこのソリューションに取り組むのに役立つ非常に優れたスクリプトを見つけました。ただし、応答xmlが少し異なっていたため、そのスクリプトを少し変更しただけで、これが私のバージョンです。

function upload_file_insert_via_soap_obj( $token, $csv_file )
{
    try
    {
        $wsdl_loc = 'https:XXX/apibatchmember/services/BatchMemberService?wsdl';

        $soap_Object = new MTOMSoapClient( $wsdl_loc, array( 'cache_wsdl' => WSDL_CACHE_NONE, 'trace' => true ) );

        $parameters['token'] = $token;
        $parameters['insertUpload']['fileName'] = "insertMemberTest.txt";
        $parameters['insertUpload']['fileEncoding'] = "UTF-8";
        $parameters['insertUpload']['separator'] = ",";
        $parameters['insertUpload']['skipFirstLine'] = "false";
        $parameters['insertUpload']['autoMapping'] = "true"; 

        $parameters['file'] = file_get_contents( "insertMemberTest.txt" );

        $results = $soap_Object->uploadFileInsert( $parameters );

        $upload_id = $results->return;

        echo "<br/>upload_id: ".$upload_id;  
        return $upload_id;  
    }
    catch ( Exception $exception )
    {
        echo "EX REQUEST: " . $soap_Object->__getLastRequest() . "<br/>";
        echo "EX RESPONSE: " . $soap_Object->__getLastResponse() . "<br/>";
        echo "<br/>Response var dump: "; var_dump( $soap_Object->__getLastResponse() ); echo "<br/>";

        echo '<br/><br/> Exception: '.$exception->getMessage()."<br/>";
        var_dump( $exception );
    }
}


/**
* This client extends the ususal SoapClient to handle mtom encoding. Due
* to mtom encoding soap body has test apart from valid xml. This extension
* remove the text and just keeps the response xml.
*/

class MTOMSoapClient extends SoapClient 
{

    public function __doRequest( $request, $location, $action, $version, $one_way = 0 ) 
    {
        $response = parent::__doRequest( $request, $location, $action, $version, $one_way );
        //if resposnse content type is mtom strip away everything but the xml.
        if ( strpos( $response, "Content-Type: application/xop+xml" ) !== false ) 
        {
            //not using stristr function twice because not supported in php 5.2 as shown below
            //$response = stristr(stristr($response, "<s:"), "</s:Envelope>", true) . "</s:Envelope>";
            $tempstr = stristr( $response, "<soap:" );
            $response = substr( $tempstr, 0, strpos( $tempstr, "</soap:Envelope>" ) ) . "</soap:Envelope>";
        }
        //log_message($response);
        return $response;
    }

}
于 2012-12-10T04:47:46.610 に答える
0

< configSections >が< configuration >の最初の要素ではなかったため、この問題が発生しました。

于 2015-02-09T05:45:26.740 に答える
0

これを配置するのに適切な場所かどうかはわかりませんが、WindowsサービスをWSDLに接続するのに苦労していました(自動生成されたWeb参照を使用)。

ここで元のポスターと同じエラーが発生していました。WCFを使用していないため、app.configが機能せず、サービスが開始されませんでした。私はMSDNでAjayChigurupatiが変更すると述べている投稿を見つけました

public partial class WsdlService : System.Web.Services.Protocols.SoapHttpClientProtocol {...}

public partial class WsdlService : Microsoft.Web.Services3.WebServicesClientProtocol {...}

Microsoft.Web.Services3(プロジェクトへの参照を必ず追加してください)

これでブールプロパティにアクセスできるようにRequireMtomなり、呼び出し元の関数を次のように囲むことができます。

    public DownloadResponse downloadDataFile([System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] DownloadRequest Request) {
        RequireMtom = true; // ADDED
        object[] results = this.Invoke("downloadDataFile", new object[] {
                    Request});
        RequireMtom = false; // ADDED
        return ((DownloadResponse)(results[0]));
    }

うまくいけば、これは将来同じ問題を抱えている他の誰かを助けるでしょう。

于 2017-05-31T17:05:41.497 に答える