2012-04-24 53 views
2

我有一個問題...我探索了整個互聯網,我不知道我在做什麼錯。Wcf 3.5 - 具有不同綁定和SOAP的不同端點

問題:WCF的Web服務,.NET Framework 3.5的,2個不同類型的客戶機(手持設備及一般計算機)

我想要做的是創造2個diferent端點,一個與basicBinding(對於SOAP請求)和其他與wsBinding(通常爲計算機)

所以我走通的web.config和我創建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; 
} 

也許我對編程發送是錯誤的合同和SOAP消息的假設......

+0

打開wcf跟蹤並得到確切的錯誤:http://blogs.msdn.com/b/madhuponduru/archive/2006/05/18/601458.aspx – 2012-04-24 18:02:20

+0

編輯。謝謝你的時間球員 – JTH 2012-04-25 07:34:46

+0

肥皂頭似乎是錯誤的。你可以在wsdl中看到正確的一個。 – 2012-04-25 10:15:23

回答

0

一般情況下,這是非常不好的做法 - 你不應該以這種方式手動創建對WCF服務的SOAP請求。如果您要利用開箱即用的WCF請求/回覆範例而不是手動設置標題,那更好。

我會推薦的是創建一個替代的例子,您可以實現同樣的開箱即用(可能DataContracts,OperationContracts和ServiceContracts在客戶端,也許利用WebHttpBehavior和WebHttpBinding )。檢查在該場景中發送和接收的確切消息,並逐字逐個仔細檢查這些消息與您在此處發送的消息的不同。

另外,很難說只要你提供的細節你可能做錯了什麼。

這裏是我的建議:

一般來說,一旦你這樣做,你應該有更多關於服務端會發生什麼變化的信息,並且可以很快診斷問題。試試吧,請回報! :)

+0

感謝您的建議。讓我們試試 – JTH 2012-04-28 11:21:34

+0

抱歉,延遲。你的建議讓我注意到了真正的問題。肥皂消息沒有需要的值。 – JTH 2012-05-27 10:34:13

相關問題