2011-02-16 59 views
3

我正在使用WCF客戶端來使用非WCF SOAP 1.2 Web服務。當收到如下所示的SOAP錯誤時,我收到ProtocolException而不是FaultException。通信綁定沒有問題,請求正在成功處理。但我無法訪問我的WCF客戶端中的錯誤。有任何想法嗎?爲什麼WCF客戶端沒有將Fault Fault作爲FaultException接收?

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:wsr="http://docs.oasis-open.org/wsrf/r-2" xmlns:xmime5="http://www.w3.org/2005/05/xmlmime" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:wsbf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:ns10="http://www.onvif.org/ver10/events/wsdl/PausableSubscriptionManagerBinding" xmlns:ns3="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding" xmlns:ns4="http://www.onvif.org/ver10/events/wsdl/EventBinding" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:ns5="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding" xmlns:ns6="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding" xmlns:ns7="http://www.onvif.org/ver10/events/wsdl/NotificationConsumerBinding" xmlns:ns8="http://www.onvif.org/ver10/events/wsdl/PullPointBinding" xmlns:ns9="http://www.onvif.org/ver10/events/wsdl/CreatePullPointBinding" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl"> 
    <SOAP-ENV:Header/> 
    <SOAP-ENV:Body> 
     <SOAP-ENV:Fault> 
     <SOAP-ENV:Code> 
      <SOAP-ENV:Value>SOAP-ENV:Sender</SOAP-ENV:Value> 
      <SOAP-ENV:Subcode> 
       <SOAP-ENV:Value>ter:InvalidArgVal</SOAP-ENV:Value> 
       <SOAP-ENV:Subcode> 
        <SOAP-ENV:Value>ter:NoSource</SOAP-ENV:Value> 
       </SOAP-ENV:Subcode> 
      </SOAP-ENV:Subcode> 
     </SOAP-ENV:Code> 
     <SOAP-ENV:Reason> 
      <SOAP-ENV:Text xml:lang="en">Not exist</SOAP-ENV:Text> 
     </SOAP-ENV:Reason> 
     <SOAP-ENV:Detail> 
      <SOAP-ENV:Text xml:lang="en">The requested VideoSource does not exist.</SOAP-ENV:Text> 
     </SOAP-ENV:Detail> 
     </SOAP-ENV:Fault> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

System.ServiceModel.ProtocolException

「遠程服務器返回一個意外的響應:(400)錯誤的請求

StackTrace 
    "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.Dispatcher.RequestChannelBinder.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.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) 
    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 

    Exception rethrown at [0]: 
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
    at OnvifProxy.ImagingPort.SetImagingSettings(String VideoSourceToken, ImagingSettings20 ImagingSettings, Boolean ForcePersistence) 
    at OnvifProxy.ImagingPortClient.SetImagingSettings(String VideoSourceToken, ImagingSettings20 ImagingSettings, Boolean ForcePersistence) in D:\..\Proxies\OvifServices.cs:line 19005 
    at Integral.Common.IPCameras.ONVIF.Services.ImagingService.SetImageSettings(String pVideoSourceToken, ImagingSettings20 pImageSettings) in D:\..\Services\ImagingService.cs:line 375" string 
+0

如果您發佈代碼,XML或數據樣本,請**在文本編輯器中突出顯示這些行,然後單擊編輯器工具欄上的「代碼示例」按鈕(「{}」)以精確地設置格式和語法突出顯示它! – 2011-02-17 05:48:56

+0

請問您可以發佈ProtocolException的堆棧跟蹤嗎? – 2011-02-17 10:04:17

回答

0

我建議使用Fiddler攔截原始響應在。在這些情況下(互操作性),最好是完全繞過WCF,並在它「到達網絡上」時讀取響應消息。嘗試通過WCF調試非WCF故障或反序列化錯誤只會讓您頭痛。=)

大多數情況下,查看原始響應會將問題指向拇指痛處。

0

我認爲你遇到的問題是因爲服務器返回400 HTTP響應代碼。顯然,Silverlight客戶端無法訪問200以外響應代碼的消息體。

如果您控制了服務器,您可以修改它以發送200響應代碼而不是400,但是如果您沒有服務器控制權,則需要修改客戶端以接受除以外的響應代碼200.

我發現一些指令here將客戶端改爲使用替代HTTP協議棧。我遇到了同樣的問題(但HTTP響應代碼爲500),並解決了這個問題。所有你需要做的就是在你的Silverlight應用程序的開頭添加以下代碼(例如,在構造函數MainPage類):

bool registerResult = WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp); 
0

是被稱爲標記中的IsOneWay = true屬性的方法生成的代理類?

如果接收到的SOAP錯誤沒有回傳通道,但WCF可以用其他方式取回回來,這顯示爲ProtocolException。據我所知,你需要有IsOneWay = false來獲得SOAP錯誤。