2011-03-21 115 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