2011-03-21 113 views
1

我正在使用我無法控制的服務器使用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優雅地接受迴應。

+0

你能給出完整的堆棧跟蹤嗎?你知道肥皂服務的語言/框架嗎? – 2011-03-21 19:55:13

+0

用堆棧跟蹤更新了問題。據我所知,後端正在使用兼容jax-rs的rest框架 – 2011-03-22 10:05:19

+0

,它會拋出相同的異常,即使我通過http調試器將204無內容更改爲200 OK,所以我認爲這不是問題,而是WCF期望的響應正文或者其他東西 – 2011-03-22 10:43:19

回答

0

我遇到了同樣的問題,因爲我對服務代碼的控制權爲零。這是方法的簽名,從我創建的服務引用Visual Studio 2010中採取:

 [System.ServiceModel.OperationContractAttribute(IsOneWay=false, Action="NotificaMessaggioAssenza")] 
    void NotificaMessaggioAssenza(string CodiceMessaggio, string StatoRecapito); 

我挺過來了編寫什麼也沒做,但檢查得到的答覆是空的自定義消息檢查,如果是,用適當的類型的空單,從動作,命名空間和方法名稱推斷,這結束了(一些試驗和錯誤之後)取代它成爲被序列化爲:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
<s:Header> 
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://rti.mediaset.it/soa/Turni/RPARS/RPARS_PortType/NotificaMessaggioAssenzaResponse</Action> 
</s:Header> 
<s:Body> 
<NotificaMessaggioAssenzaResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://rti.mediaset.it/soa/Turni/RPARS" /> 
</s:Body> 
</s:Envelope> 

這些鏈接幫了我很多:1234