我正在使用我無法控制的服務器使用WCF Web服務。不返回任何數據的方法在HTTP中完全可以使用HTTP代碼204,但是我有處理響應的WCF自身的問題(所有其他返回400的方法都可以正常工作)。WCF HTTP 204響應
這裏是我的方法聲明:
[OperationContract]
[WebInvoke(UriTemplate = "methodpath/V1",
RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
void Operation1(
[MessageParameter(Name = "username")]
string userName,
[MessageParameter(Name = "password")]
string password);
錯誤調用該方法後,我得到: 的CommunicationException:錯誤在反序列化的回覆消息的身體操作「Operation1」。 OperationFormatter無法反序列化消息中的任何信息,因爲消息是空的(IsEmpty = true)。
也嘗試過使用IsOneWay = true: InvalidOperationException:單向操作返回一個非空消息,其中Action =''。
這裏是原始的HTTP響應:
HTTP/1.1 204 No Content
Set-Cookie: ...
Content-Length: 0
Connection: Close
Date: Mon, 21 Mar 2011 18:41:37 GMT
異常堆棧跟蹤:
服務器堆棧跟蹤:
at System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.DeserializeReply(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.DemultiplexingClientMessageFormatter.DeserializeReply(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.CompositeClientFormatter.DeserializeReply(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
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)
將不勝感激的人誰擁有一個想法如何強制WCF優雅地接受迴應。
你能給出完整的堆棧跟蹤嗎?你知道肥皂服務的語言/框架嗎? – 2011-03-21 19:55:13
用堆棧跟蹤更新了問題。據我所知,後端正在使用兼容jax-rs的rest框架 – 2011-03-22 10:05:19
,它會拋出相同的異常,即使我通過http調試器將204無內容更改爲200 OK,所以我認爲這不是問題,而是WCF期望的響應正文或者其他東西 – 2011-03-22 10:43:19