我有一個問題...我探索了整個互聯網,我不知道我在做什麼錯。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消息的假設......
打開wcf跟蹤並得到確切的錯誤:http://blogs.msdn.com/b/madhuponduru/archive/2006/05/18/601458.aspx – 2012-04-24 18:02:20
編輯。謝謝你的時間球員 – JTH 2012-04-25 07:34:46
肥皂頭似乎是錯誤的。你可以在wsdl中看到正確的一個。 – 2012-04-25 10:15:23