我正在从我无法控制的服务器上使用WCF Web服务。不返回任何数据的方法触发HTTP代码204,这在HTTP方面完全没问题,但是我有一个WCF本身处理响应的问题(返回400的所有其他方法工作正常)。
这是我的方法声明:
[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无法反序列化Message中的任何信息,因为Message为空(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 :(得分:0)
我认为您需要编写自定义渠道类。请查看此链接Channel Model Overview
答案 1 :(得分:0)
在我无法控制服务代码的情况下,我遇到了与您相同的问题。这是该方法的签名,取自为我创建的服务参考Visual Studio 2010:
[System.ServiceModel.OperationContractAttribute(IsOneWay=false, Action="NotificaMessaggioAssenza")]
void NotificaMessaggioAssenza(string CodiceMessaggio, string StatoRecapito);
我完成了编写自定义消息检查程序,但只检查回复是否为空,如果是,请将其替换为相应类型的空类型,从Action,Namespace和方法名称推断,结束up(经过一些试验和错误)被序列化为:
<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>