尝试实现ONVIF服务器

时间:2016-03-07 16:41:25

标签: c# wcf soap onvif

我正在尝试将{C#WCF服务器实现为http://www.onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl的ONVIF规范。我使用

生成了合同代码
 SvcUtil.exe http://www.onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl

生成DevicePTZ接口。然后,我创建了生成的接口的实现,并使用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 Action不匹配, 'http://www.onvif.org/ver10/device/wsdl/GetScopes'。“。 Wireshark显示请求没有任何SOAP标头。但是,据我所知,客户端是针对相同的WSDL文件开发的。

我恐怕我对ONVIF,SOAP,Web服务和WCF都是全新的,所以我不知道问题出在哪里。我已经看到了修改客户端的各种建议,但这不是一个选项。

1 个答案:

答案 0 :(得分:0)

答案是使用自定义绑定来删除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

相关问题