누구나 WCF를 사용하여 Onvif 카메라 검색의 간단한 예가 있습니까? 또는 WCF를 사용하여 Onvif 표준을 사용하여 카메라에 명령을 보내는 다른 예는 무엇입니까? Onvif DM, Onvif 장치 테스트 도구 및 Onvif 프로그래밍 가이드를 알고 있습니다. 그러나 구현 방법을 모릅니다. WCF 및 Onvif 간단한 예제
는답변
는 system.serviceModel 및 System.ServiceModel.Discovery 어셈블리를 추가 감사드립니다. 이 코드입니다 :
// perform the onvif search (this is the MAIN)
public static IEnumerable<EndpointDiscoveryMetadata> SearchOnvifDevices()
{
// object used to define the search criteria to find onvif device on the network
var findCriteria = new FindCriteria();
// what device type to find? this is required
var contractTypeName = "NetworkVideoTransmitter"; // the other possible value is 'Device'
var contractTypeNamespace = "http://www.onvif.org/ver10/network/wsdl";
// those parametes are defined by onvif standard
findCriteria.ContractTypeNames.Add(new XmlQualifiedName(contractTypeName, contractTypeNamespace));
// you can canfigure the search with TimeOut, MaxResults, Scope, DeviceType, MaxResponseDelay, TransportSettings.TimeToLive, ...
findCriteria.MaxResults = 100;
findCriteria.Duration = new TimeSpan(10000);
// ...
//// you can specify scopes to restrict the search
//SetScopes(findCriteria, new[] { "onvif://www.onvif.org/type/ptz" });
// object used to search the devices using the FindCriteria.
var discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005));
// search
var findResponse = discoveryClient.Find(findCriteria);
return findResponse.Endpoints;
}
// set scopes to find devices that only match the specifieds scopes
public static void SetScopes(FindCriteria findCriteria, IEnumerable<string> scopes)
{
findCriteria.ScopeMatchBy = FindCriteria.ScopeMatchByExact;
if (scopes != null)
{
foreach (var item in scopes)
findCriteria.Scopes.Add(new Uri(item));
}
// for example:
// a device can have set the following scopes:
// onvif://www.onvif.org/type/ptz
// onvif://www.onvif.org/hardware/D1-566
// onvif://www.onvif.org/location/country/china
// onvif://www.onvif.org/location/city/bejing
// onvif://www.onvif.org/name/ARV-453
// then if you perform the search with the scope 'onvif://www.onvif.org/location/country/china' it will resolve the device
// but if the search include the scope 'onvif://www.onvif.org/hardware/D1' then it will not.
}
// you can use this method to get parse endpoints to device
public static IEnumerable<Device> GetDevices(IEnumerable<EndpointDiscoveryMetadata> endpoints)
{
var result = new List<Device>();
var id = 0;
foreach (var endpoint in endpoints)
{
foreach (var listenUri in endpoint.ListenUris)
{
var newDevice = new Device
{
Id = id,
ListenUri = listenUri,
EndpointDiscoveryMetadata = endpoint
};
result.Add(newDevice);
id++;
}
}
return result;
}
// class used to identify a Device
public class Device
{
// id to identify the device
public int Id;
// uri where the device is listening
public Uri ListenUri;
// endpoint where the device was founded
public EndpointDiscoveryMetadata EndpointDiscoveryMetadata;
}
당신은 다음과 같이 사용할 수 있습니다 :
// discover endpoints
var endpoints = SearchOnvifDevices();
// if you want, parse to devices
var devices = GetDevices(endpoints);
, 난 따라서 테스터 수는 없지만,이 코드를 손에 어떤 장치가없는하세요 작동해야합니다. 어떤 제안이나 오류도 댓글을 달았습니다.
코드 응답 및 공유에 큰 감사드립니다 !! 나는 아직도이 코드로 내 Onvif 카메라를 발견하려고 노력하고있다. 이 코드를 사용할 때 네트워크를 전혀 검색하지 않는 것 같습니다. 그래서, 나는 당신의 코드를 기반으로 의사 소통하는 방법을 계속 연구 할 것이다. –
@BorisP findCriteria의 지속 시간 (findCriteria.Duration = new TimeSpan (100000000);)을 늘리고 장치를 검색 할 수 있는지 확인하려면 장치를 구성해야합니다. –
안녕하세요. 나는 최근에 우리의 네트워크 관리자가 WS 검색을 어떻게 든 비활성화했다고 생각했습니다.> :(당신의 솔루션이 작동합니다 !! 큰 감사합니다! :) 그러나, 여전히 카메라를 찾을 수 없습니다. Onvif 장치 관리자는 광산을 포함하여 네트워크상의 모든 카메라를 찾을 수 있지만 솔루션은 네 개 중 세 개만 찾습니다. 젠장;) 나는 당신의 코드의 수정을 답으로 게시 할 것이다. 그러나 만약 당신이 어떤 제안이라도 있으면 감사 할 것이다. :) –
수정
#region SearchOnvifDev-Proba1
private static void SearchOnvifDev()
{
ServicePointManager.Expect100Continue = false;
var contractTypeName = "Device"; // the other possible value is 'Device' or 'NetworkVideoTransmitter'
var contractTypeNamespace = "http://www.onvif.org/ver10/network/wsdl";
var endPoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);
var discoveryClient = new DiscoveryClient(endPoint);
FindCriteria findCriteria = new FindCriteria();
//visak ispod
findCriteria.ContractTypeNames.Add(new XmlQualifiedName(contractTypeName, contractTypeNamespace));
findCriteria.Duration = TimeSpan.MaxValue;
findCriteria.MaxResults = 1000000;
discoveryClient.FindAsync(findCriteria);
//events
discoveryClient.FindProgressChanged += discoveryClient_FindProgressChanged;
discoveryClient.FindCompleted += discoveryClient_FindCompleted;
Console.ReadKey();
}
#endregion
#region endEvent for discovery client
static void discoveryClient_FindCompleted(object sender, FindCompletedEventArgs e)
{
Console.WriteLine("the end");
}
#endregion
#region changeEvent for discovery client
static void discoveryClient_FindProgressChanged(object sender, FindProgressChangedEventArgs e)
{
var lines = "\r\n--------" + DateTime.Now.ToString() + "\r\n" + e.EndpointDiscoveryMetadata.Address.Uri.AbsoluteUri.ToString();
Console.WriteLine("\r\n--------" + DateTime.Now.ToString() + "\r\n" + e.EndpointDiscoveryMetadata.Address.Uri.AbsoluteUri.ToString());
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"info.txt", true))
{
file.WriteLine(lines);
}
foreach (var item in e.EndpointDiscoveryMetadata.ListenUris)
{
string uri = item.OriginalString;
Console.WriteLine(uri.ToString());
//this camera isnt found :(
if (uri.Contains("http://192.168.4.230/"))
{
Console.WriteLine("BINGO");
}
}
}
#endregion
- 1. REST WCF 데이터 서비스가있는 간단한 예제
- 2. MSMQ를 사용하는 간단한 WCF 예제 온라인이 있습니까?
- 3. Gsoap, ONVIF 및 검색
- 4. 공동 및 반항의 간단한 예제
- 5. 간단한 C# 정규식 예제
- 6. basicHttpsBinding을 사용하는 WCF (SOAP)의 캐시 - 간단한 예제
- 7. 간단한 GoLang SSL 예제
- 8. 간단한 ASP.NET MVC 예제
- 9. 간단한 XSocket.Net 예제 시작 및 실행 방법
- 10. Ajax 및 Node.js의 간단한 버튼 클릭 예제?
- 11. matlab을 이용한 분류 및 테스트를위한 간단한 예제
- 12. Node.js를 - 간단한 예제 및 EPERM 오류
- 13. 로봇 프레임 워크 및 SeleniumLibrary 간단한 예제
- 14. 범주, Monoid 및 Monad를 설명하기위한 간단한 예제?
- 15. 배치 파일 및 창 스케줄러의 간단한 예제
- 16. 기존 라이브러리가없는 Asp.net 및 OAuth 간단한 예제
- 17. 간단한 SOAP 예제
- 18. C++ 큐 - 간단한 예제
- 19. MVC 가장 간단한 예제
- 20. 처리/Java - 간단한 예제
- 21. NSXMLParser 간단한 예제
- 22. WebApplicationInitializer 간단한 예제
- 23. Proguard 간단한 예제 오류
- 24. window.requestFileSystem() 함수가있는 간단한 예제
- 25. 간단한 kivy 탭 예제
- 26. 간단한 MediaElement 클래스 예제
- 27. 간단한 JNI 예제 Android
- 28. 간단한 mod_rewrite 예제
- 29. 간단한 Java 제네릭 예제
- 30. 은 간단한 예제
안녕하세요, 어쩌면 너무 늦게이며 이미 해결책을 찾았지만, 내가 네트워크에 ONVIF 장치를 찾을 수있는 간단한 C# 코드를 가지고, 그것은 매우 간단합니다. WCF 솔루션을 제공 할 수 있지만 몇 시간이 필요합니다. –
이봐, 너무 늦은 적이 없어. 도와 주셔서 감사합니다 :))) 좋은 출발점이 될 수 있습니다 :) 물론, 시간이 걸릴 수 있습니다. –