簡體   English   中英

WCF 3.5-具有不同綁定和SOAP的不同端點

[英]Wcf 3.5 - Different endpoints with different bindings and SOAP

我有問題...我瀏覽了整個互聯網,但我不知道自己在做什么錯。

問題:WCF Web服務,.Net Framework 3.5、2種不同類型的客戶端(手持設備和普通計算機)

我想做的是創建2個不同的端點,一個端點具有basicBinding(用於SOAP請求),另一個具有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與自定義客戶端,但無法找到正在發生的情況

有什么建議或建議嗎?

謝謝你的時間

編輯:

啟用S​​vc跟蹤后,我遇到了幾個異常:

<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;
}

也許我對以編程方式發送的合同和肥皂消息的假設是錯誤的...

通常,這是非常糟糕的做法-不應以這種方式手動將SOAP請求創作到WCF服務。 如果您要利用現成的WCF請求/答復范例而不是手動設置標頭,則更好。

我建議創建一個替代示例,在該示例中您可以立即實現相同的功能(可能在客戶端使用DataContracts,OperationContracts和ServiceContracts,也可以利用WebHttpBehavior和WebHttpBinding)。 檢查在這種情況下發送和接收的確切消息,並逐個字符仔細檢查這些消息與您在此處發送的消息有何不同。

另外,僅憑提供的細節很難分辨出您可能還會做錯什么。

這是我的建議:

通常,一旦執行此操作,您就應該在服務端獲取更多有關時髦問題的信息,並且可以很快地診斷出問題。 試試看,請回報! :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM