【发布时间】:2020-04-15 10:48:02
【问题描述】:
我遇到了对 ONVIF 设备的 SOAP 1.2 请求。
我的代码是:
var c = "http://192.168.31.12:5000/onvif/device_service";
var wsBinding = new WSHttpBinding(SecurityMode.None);
wsBinding.Name = "My WSHttpBinding";
wsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
CustomBinding l_CustomBinding = new CustomBinding(wsBinding);
MessageEncodingBindingElement l_EncodingElement =
l_CustomBinding.Elements.Find<MessageEncodingBindingElement>();
l_EncodingElement.MessageVersion = MessageVersion.Soap12;
EndpointAddress endpointAddress = new EndpointAddress(c);
fgdfsdfsdg.ServiceReference1.DeviceClient cl = new ServiceReference1.DeviceClient(l_CustomBinding, endpointAddress);
fgdfsdfsdg.ServiceReference1.GetDeviceInformationRequest inValue = new fgdfsdfsdg.ServiceReference1.GetDeviceInformationRequest();
var Q = cl.GetDeviceInformationAsync(inValue).Result;
我在 Wireshark 中看到的:
POST /onvif/device_service HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver10/device/wsdl/GetDeviceInformation"
Host: 192.168.31.12:5000
Content-Length: 261
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
WS 的期望:
POST /onvif/device_service HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver10/device/wsdl/GetDeviceInformation"
Host: 192.168.31.12:5000
Content-Length: 261
Accept-Encoding: gzip, deflate
Connection: Close
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetDeviceInformation xmlns="http://www.onvif.org/ver10/device/wsdl"/></s:Body></s:Envelope>
我应该在我的代码中添加什么以使 C# 也发送请求正文,而不仅仅是 HTTP POST 请求中的标头?
【问题讨论】:
标签: c# web-services wcf soap