我正试图在http://www.onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl上实现一个符合ONVIF规范的C# WCF服务器。我已经使用以下命令生成了合同代码
SvcUtil.exe http://www.onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl它生成Device和PTZ接口。然后,我创建了生成的接口的实现,并使用如下所示的ServiceHost公开该接口:
serviceHost = new ServiceHost(typeof(OnvifImpl), baseUri);
serviceHost.AddServiceEndpoint(typeof(Device), new WSHttpBinding(), "device_service");
serviceHost.AddServiceEndpoint(typeof(PTZ), new WSHttpBinding(), "ptz");当我将Onvif Device Manager 2.2.250 (https://sourceforge.net/projects/onvifdm/)指向我的服务器时,我在服务器中得到一个异常:“消息上指定的SOAP操作'‘与HTTP SOAP操作’http://www.onvif.org/ver10/device/wsdl/GetScopes‘不匹配”。Wireshark显示该请求没有任何SOAP标头。但是,据我所知,客户端是针对相同的WSDL文件开发的。
恐怕我对ONVIF、SOAP、Web服务和WCF完全陌生,所以我不知道问题出在哪里。我已经看到了修改客户端的各种建议,但这不是一个选项。
发布于 2016-03-09 18:34:38
答案是使用自定义绑定删除WS-Addressing。这就是客户端代码所做的事情,所以我也执行了相同的匹配操作。我不能完全确定这是一个“解决方案”还是“变通办法”,但它让这两个人开始讨论。
var binding = new CustomBinding(new BindingElement[] {
new TextMessageEncodingBindingElement(MessageVersion.Soap12, Encoding.UTF8),
new HttpTransportBindingElement(),
});
serviceHost.AddServiceEndpoint(typeof(Device), binding, "device_service");
serviceHost.AddServiceEndpoint(typeof(PTZ), binding, "ptz");关键区别在于使用MessageVersion.Soap12而不是默认的MessageVersion.Soap12WSAddressing10。
https://stackoverflow.com/questions/35849191
复制相似问题