将WCF绑定从wsHttp更改为netTcp

时间:2011-08-03 08:00:19

标签: .net wcf

我遇到了要更改为NetTcpBinding的WCF服务WsHttpBinding的问题。 以前,我在IIS7本地计算机上设置了服务,它与WsHttpBinding配合使用。

此服务的代理服务器有一个CustomBehavior,它在发送请求消息之前添加两个消息头

当我将绑定更改为NetTcpBinding时,我在日志中得到以下异常..

 Exception: System.ServiceModel.ServiceActivationException: Service /ConsignmentService/Consignment.svc cannot be activated due to an exception during compilation. The exception message is: Exception has been thrown by the target of an invocation ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ServiceModel.MessageHeaderException: There is not a header with the name "ClientID" og namespace 'http://AmphoraExtension/Header' in the message.
   ved System.ServiceModel.Channels.MessageHeaders.GetHeader[T](String name, String ns, XmlObjectSerializer serializer)
   ved System.ServiceModel.Channels.MessageHeaders.GetHeader[T](String name, String ns)

这适用于wsHttpBinding,但是当切换到NetTcpBinding时却没有。 我在这里缺少什么?

2 个答案:

答案 0 :(得分:1)

对CustomBehaviour不太确定,但我刚刚遇到了在netTcp下在IIS上运行WCF服务的完全相同的问题。在这里查看我的问题:

WCF netTcpBinding hosted on IIS7.5 Stops Working

经过多次调整后,我最终回答了自己的问题,并发布了一份清单,用于获取在IIS上运行的netTcp服务。

答案 1 :(得分:0)

自己解决了。

这是我的坏事。在带有参数和Header的实际请求之前向WCF服务器发出了请求,这迫使Service类被实例化。在构造函数中,应该存在标题数据周围的逻辑。我为此做了一个解决方法