首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用OnVif连接到启用C#的摄像机

无法使用OnVif连接到启用C#的摄像机
EN

Stack Overflow用户
提问于 2013-08-09 15:05:35
回答 2查看 6.1K关注 0票数 3

我是第一次与IPCams合作,我正在尝试连接到OnVif摄像头。我看过各种论坛和堆栈溢出,我想出了下面的代码,我知道代码没有什么用处,但现在它只是一个概念的证明。它在我的网络上找到了所有的4个摄像头,然后我手动连接到其中的一个,以提取一些信息,比如,GetServices,

在这个阶段,我得到了一个400错误的响应错误。我在WireShark中来回查看了流量,就我所知(安全和加密根本不是我的领域),关于生成的密码,一切似乎都正常。

有人能帮忙或建议吗?

代码语言:javascript
复制
class Program
{

    static void Main(string[] args)
    {
        var endPoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);

        var discoveryClient = new DiscoveryClient(endPoint);

        discoveryClient.FindProgressChanged += discoveryClient_FindProgressChanged;

        discoveryClient.FindCompleted += discoveryClient_FindCompleted;

        FindCriteria findCriteria = new FindCriteria();
        findCriteria.Duration = new TimeSpan(0, 0, 2);//TimeSpan.MaxValue;
        findCriteria.MaxResults = int.MaxValue;
        discoveryClient.FindAsync(findCriteria);

        Console.ReadKey();
    }

    private static void discoveryClient_FindCompleted(object sender, FindCompletedEventArgs e)
    {
        Console.WriteLine("Discovery complete");
    }

    static void discoveryClient_FindProgressChanged(object sender, FindProgressChangedEventArgs e)
    {

        foreach (var u in e.EndpointDiscoveryMetadata.ListenUris)
        {

            string uri = u.OriginalString;

            if (uri.Contains("http://192.168.1.162/onvif/device_service"))
            {

                Console.WriteLine(uri);

                EndpointAddress serviceAddress = new EndpointAddress(uri);

                HttpTransportBindingElement httpBinding = new HttpTransportBindingElement();

                httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest;

                var messegeElement = new TextMessageEncodingBindingElement();

                messegeElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None);

                CustomBinding bind = new CustomBinding(messegeElement, httpBinding);

                DeviceClient client = new DeviceClient(bind, serviceAddress);

                // Add our custom behavior - this require the Microsoft WSE 3.0 SDK
                PasswordDigestBehavior behavior = new PasswordDigestBehavior("test", "test");

                client.Endpoint.Behaviors.Add(behavior);

                foreach (Service s in client.GetServices(false))
                    Console.WriteLine(s.ToString());

                client.Open();

                Console.WriteLine("WSDL = " + client.GetWsdlUrl());
                Console.WriteLine("DateTime = " + client.GetSystemDateAndTime());

                string a1, b1, c1, d1;
                Console.Write(client.GetDeviceInformation(out a1, out b1, out c1, out d1));

            }
        }
    }
}

Wireshark (用户名和密码都是测试的)

代码语言:javascript
复制
POST /onvif/device_service HTTP/1.1

Content-Type: application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver10/device/wsdl/GetServices"

Host: 192.168.1.162

Content-Length: 1232

Expect: 100-continue

Accept-Encoding: gzip, deflate

Connection: Keep-Alive



<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
  <s:Header>
    <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo7uVma6HRQNDh2l6T2ZDNzIAAAAA2/ITWE91IUaNFF3UObayz0mz6QvnZppBlYrNJBd1QGsACQAA</VsDebuggerCausalityData>
    <Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <wsse:UsernameToken wsu:Id="SecurityToken-56f9081e-e9b4-4660-9158-7419af1efde0" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:Username>test</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">WSKWE5XjP5aPiIiA9JicCOYoDkU=</wsse:Password>
        <wsse:Nonce>6sYgS41VHsWKj7n8TNKFjA==</wsse:Nonce>
        <wsu:Created>2013-08-09T14:52:45Z</wsu:Created>
      </wsse:UsernameToken>
    </Security>
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <GetServices xmlns="http://www.onvif.org/ver10/device/wsdl">
      <IncludeCapability>false</IncludeCapability>
    </GetServices>
  </s:Body>
</s:Envelope>HTTP/1.1 400 Bad Request

Server: gSOAP/2.7

Content-Type: application/soap+xml; charset=utf-8

Content-Length: 2751

Connection: close



<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:xmime="http://tempuri.org/xmime.xsd" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2" xmlns:aa="http://www.axis.com/vapix/ws/action1" xmlns:aev="http://www.axis.com/vapix/ws/event1" xmlns:tan1="http://www.onvif.org/ver20/analytics/wsdl/RuleEngineBinding" xmlns:tan2="http://www.onvif.org/ver20/analytics/wsdl/AnalyticsEngineBinding" xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:tev1="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding" xmlns:tev2="http://www.onvif.org/ver10/events/wsdl/EventBinding" xmlns:tev3="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:tev4="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:tnsaxis="http://www.axis.com/2009/event/topics">
  <SOAP-ENV:Header>
    <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo7uVma6HRQNDh2l6T2ZDNzIAAAAA2/ITWE91IUaNFF3UObayz0mz6QvnZppBlYrNJBd1QGsACQAA</VsDebuggerCausalityData>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <SOAP-ENV:Fault SOAP-ENV:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
      <SOAP-ENV:Code>
        <SOAP-ENV:Value>SOAP-ENV:Sender</SOAP-ENV:Value>
        <SOAP-ENV:Subcode>
          <SOAP-ENV:Value>ter:NotAuthorized</SOAP-ENV:Value>
        </SOAP-ENV:Subcode>
      </SOAP-ENV:Code>
      <SOAP-ENV:Reason>
        <SOAP-ENV:Text xml:lang="en">Sender not authorized</SOAP-ENV:Text>
      </SOAP-ENV:Reason>
      <SOAP-ENV:Detail>
        <SOAP-ENV:Text>The action requested requires authorization and the sender is not authorized</SOAP-ENV:Text>
      </SOAP-ENV:Detail>
    </SOAP-ENV:Fault>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我在相机上启用了onvif (通过使用密码"test“创建一个名为"test”的管理员用户)。相机密码是默认的“根”和“通过”,因为它是一个轴相机。

EN

回答 2

Stack Overflow用户

发布于 2013-09-04 21:13:34

以下列方式配置与摄像机的连接:

代码语言:javascript
复制
    ServicePointManager.Expect100Continue = false;
    var endPointAddress = new EndpointAddress("http://" + cameraAddress + "/onvif/device_service");
    var httpTransportBinding = new HttpTransportBindingElement { AuthenticationScheme = AuthenticationSchemes.Digest };
    var textMessageEncodingBinding = new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) };
    var customBinding = new CustomBinding(textMessageEncodingBinding, httpTransportBinding);
    var passwordDigestBehavior = new PasswordDigestBehavior(adminName, adminPassword);
    var deviceClient = new DeviceClient(customBinding, endPointAddress);
    deviceClient.Endpoint.Behaviors.Add(passwordDigestBehavior);

我知道这几乎是你所做的,但重要的是让ServicePointManager.Expect100Continue变成假的。

票数 1
EN

Stack Overflow用户

发布于 2014-11-07 14:06:07

检查相机是否启用了重放攻击保护。如果是这样,请检查计算机的时间和摄像机的时间差。根据ONVIF的规格,允许的时间差必须是+- 5秒。否则你就会犯错误。

如果这是您的情况,您有以下几种选择:

1-禁用重播攻击保护功能。不建议这样做,因为您需要在所有需要使用的相机中禁用此功能。

2-你可以同步相机的时间和你的电脑时间。同样,也不建议对同一问题的第一种选择。

3-如果您可以更改WSE 3.0的其他选项。在WSE3.0中,一旦创建了UsernameToken,就不能更改 created 属性,该属性用于创建加密。这个问题用here描述。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18149866

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档