2011-05-11 74 views
0

我使用的wsHttpBinding服務從現在開始工作得很完美。我的WPF應用程序(客戶端)已連接到它並自動每15秒從服務器接收信息。WCF奇怪的服務行爲

我已經注意到,有時(曾經在一段時間裏,有幾天是沒有問題的)我的客戶端會收到以下異常:

System.ServiceModel.ProtocolException: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<html> 
    <head> 
     <title> </title> 
     <script type="text/javascript"> 
     function bredir(d,u,r,v,c){var w,h,wd,hd,bi;var b=false;var p=false;var s=[[300,250,false],[250,250,false],[240,400,false],[336,280,false],[180,150,false],[468,60,false],[234,60,false],[88,31,false],[120,90,false],[120,60,false],[120,240,false],[125,125,false],[728,90,false],[160,600,false],[120,600,false],[300,600,false],[300,125,false],[530,300,false],[190,200,false],[470,250,false],[720,300,true],[500,350,true],[550,480,true]];if(typeof(window.innerHeight)=='number'){h=window.innerHeight;w=window.innerWidth;}else if(typeof(document.body.offsetHeight)=='number'){h=document.body.offsetHeight;w=document.body.offsetWidth;}for(var i=0;i<s.length;i++){bi=s[i];wd=Math.abs(w-bi[0]);hd=Math.abs(h-bi[1]);if(wd<=2&&hd<=2){b=true;p=bi[2];}}if(b||(w<100&&w!==0)||(h<100&&h!==0)){if(p&&self==parent){self.close();return;}return'/b'+'anner.php?w='+w+'&h='+h+'&d='+d+'&u='+u+'&r='+r+'&view='+v;}else{return c;}} 
     </script> 
    </head> 
    <body onLoad="window.l'. 

Server stack trace: 
    at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding) 
    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 
    at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) 
    at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode) 
    at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode) 
    at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 

你會在哪裏解決這個問題的任何想法?

謝謝, Camille。

+0

不確定爲什麼你在有效載荷中有這個html。我會建議看看你不能編碼xml有效載荷。 – Perpetualcoder 2011-05-11 02:42:57

回答

0

這似乎與安全協商有關。有可能你的安全上下文被緩存 - 所以當會話到期時,安全上下文不再有效,但它仍然試圖傳遞它。您可能需要檢查這一點,並且您每次都關閉連接。你可能最終不得不實施一個重試例程(你的客戶端代碼來捕獲通信異常,並在發生這種情況時拋出當前客戶端對象並創建一個新對象(類似於重試)。我不得不這樣做這在我的客戶之一。

我希望這有助於。

乾杯,瓦格納。

+0

不幸的是,保持安全會話是我必須的。如果不放棄我的身份驗證方法(和許可證選擇),我將無法重新創建連接。 – user658664 2011-05-11 05:51:23

+0

您可能可以緩存ClientCredentials對象,並在重新創建連接後將其傳回給新客戶端。 – 2011-05-11 22:11:31

1

我猜,偶爾要連接到該服務有問題,並與一個HTML錯誤頁面響應這可能是404頁面未找到或503服務不可用或500內部服務器錯誤。

+0

好吧..但我怎麼可以調試呢?我被限制在這裏的前1024個字節,並且無法從客戶端(WPF)端獲得更多... – user658664 2011-05-11 05:50:23

+0

抱歉,我的回覆遲了。我可能會開始使用[Fiddler](http://www.fiddler2.com/)之類的東西來嗅探http請求和響應。在回覆中,您會看到最有可能出現問題時返回的HTML頁面。像Fiddler這樣的工具很有用,因爲它會在將響應傳遞到應用程序之前調查響應。 – 2011-05-19 02:19:10