尝试实现ONVIF服务器的SOAP操作不匹配

问题描述:

我试图在http://www.onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl的ONVIF规范中实现C#WCF服务器。我已经生成使用尝试实现ONVIF服务器的SOAP操作不匹配

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设备管理器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都是全新的,所以我不知道问题出在哪里。我看到了各种建议来修改客户端,但这不是一种选择。

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