2

問題があります...インターネット全体を調べましたが、何が間違っているのかわかりません。

問題:WCF Webサービス、.Net Framework 3.5、2つの異なるタイプのクライアント(ハンドヘルドデバイスと通常のコンピューター)

私がやろうとしているのは、2つの異なるエンドポイントを作成することです。1つはbasicBinding(SOAPリクエスト用)を使用し、もう1つはwsBinding(通常のコンピューター用)を使用します。

そこで、web.configを使用して、2つの異なるエンドポイントに関連する2つの異なるバインディングを作成しました。

<bindings>
  <basicHttpBinding>
    <binding name="BasicBinding" openTimeout="00:10:00" receiveTimeout="23:59:00"
      sendTimeout="23:59:00" messageEncoding="Text" />
  </basicHttpBinding>
  <wsHttpBinding>
    <binding name="DefaultBinding" openTimeout="00:10:00" receiveTimeout="23:59:59"
      sendTimeout="23:59:59">
      <reliableSession inactivityTimeout="01:00:00" />
      <security mode="None">
        <transport clientCredentialType="None" />
        <message clientCredentialType="None" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="qtswsdl.QTS_ServiceBehavior"
    name="qtswsdl.QTS_Service">
    <endpoint address="http://host.com/service.svc/ForHh"
      binding="basicHttpBinding" bindingConfiguration="BasicBinding"
      name="handHeldEndPoint" contract="qtswsdl.QTSPort" />
    <endpoint address="http://host.com/service.svc/ForCp"
      binding="wsHttpBinding" bindingConfiguration="DefaultBinding"
      name="coProcessorEndPoint" contract="qtswsdl.QTSPort" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="qtswsdl.QTS_ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      <serviceThrottling maxConcurrentCalls="2147483647"maxConcurrentSessions="2147483647"
        maxConcurrentInstances="2147483647" />
    </behavior>
  </serviceBehaviors>
</behaviors>

したがって、SOAPメッセージを「http://host.com/service.svc/ForHh」に送信しようとすると、「HTTP 400-不正な要求」が発生します(/ ForCpも機能しません)

WcfTestClient.exeを使用してカスタムクライアントで試しましたが、何が起こっているのかを特定できませんでした

ヒントや提案はありますか?

御時間ありがとうございます

編集:

Svcトレースを有効にした後、いくつかの例外が発生しました。

<Message>The message with Action 'http://Host.com/Service.svc/ForHh' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</Message>

面白いのは、SOAPリクエストをプログラムで送信していることです。プログラムでSOAPリクエストを送信する場合、デフォルトでSOAP 1.1を使用して送信されるため、コントラクトを定義する必要がないことを理解しています。

リクエストを送信するコードは次のコードです。

private string SendRequestAndGetAnswerFromWebService(string methodName, string requestXml){

     StringBuilder soapRequest = new StringBuilder("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
                soapRequest.Append(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ");
                soapRequest.Append("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>");
                soapRequest.Append(requestXml);//Body
                soapRequest.Append("</soap:Body></soap:Envelope>");

                   WebRequest webRequest = WebRequest.Create(@"http://Host.com/Service.svc/" + methodName);
                   HttpWebRequest httpRequest = (HttpWebRequest)webRequest;
                   httpRequest.Method = "POST";
                   httpRequest.ContentType = "text/xml; charset=ascii";
                   httpRequest.Headers.Add("SOAPAction: " + @"http://Host.com/Service.svc/Service.svc/" + methodName);
                   httpRequest.ProtocolVersion = HttpVersion.Version11;
                   httpRequest.Credentials = CredentialCache.DefaultCredentials;
                   httpRequest.Timeout = 7000;
                   httpRequest.ContentLength = System.Text.Encoding.ASCII.GetByteCount(soapRequest.ToString());
                   Stream requestStream = httpRequest.GetRequestStream();

                   //Create Stream and send Request 
                   StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.ASCII);
                   streamWriter.Write(soapRequest.ToString());
                   //Send the request             
                   streamWriter.Close();

                   //Get the Response
                   HttpWebResponse wr = (HttpWebResponse)httpRequest.GetResponse();
                   StreamReader srd = new StreamReader(wr.GetResponseStream());
                   string resulXmlFromWebService = srd.ReadToEnd();
                   return resulXmlFromWebService;
}

プログラムで送信される契約と石鹸のメッセージについての私の仮定は間違っているかもしれません...

4

1 に答える 1

0

一般に、これは非常に悪い習慣です。この方法でWCFサービスへのSOAP要求を手動で作成しないでください。ヘッダーを手動で設定するのではなく、すぐに使用できるWCF要求/応答パラダイムを利用する方がよいでしょう。

私がお勧めするのは、同じことをすぐに実現できる代替の例を作成することです(おそらく、WebHttpBehaviorとWebHttpBindingを利用して、クライアント側でDataContracts、OperationContracts、およびServiceContractsを使用します)。そのシナリオで送受信される正確なメッセージを調べ、文字ごとに、それらのメッセージがここで送信しているメッセージとどのように異なるかを詳しく調べます。

また、提供した詳細だけから、他に何が間違っている可能性があるかを判断するのは困難です。

これが私が提案するものです:

一般に、これを行うと、サービス側で何がファンキーになっているのかについてより多くの情報が得られ、問題を非常に迅速に診断できます。試してみて、報告してください!:)

于 2012-04-26T15:35:30.090 に答える