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 Device Managerは私のものを含めてネットワーク上のすべてのカメラを見つけることができますが、あなたのソリューションは4つのうち3つしか見つけません。私は答えとしてあなたのコードの変更を投稿しますが、あなたは私が感謝する任意の提案がある場合:) –
変更
#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. 単純な例のWCF奇妙
- 2. basicHttpsBindingを使用したWCF(SOAP)のキャッシュ - 単純な例
- 3. WebApplicationInitializer単純な例
- 4. 単純なRMIコールバックの例
- 5. 単純なGWT OpenIDの例
- 6. 単純なR foreachの例
- 7. 単純な例として、C#
- 8. 単純なループ例説明
- 9. SQLAlchemy Generic Relationship単純な例
- 10. ORA-00979:単純な例
- 11. 単純ScalaFxテーブルビュー例
- 12. 単純なModelAdminの例のTemplateDoesNotExistエラー
- 13. 単純なAOPの例のUnsupportedPointcutPrimitiveException
- 14. C++の単純なスレッドの例
- 15. 単純なjQuery UIのドラッグ&ドロップの例
- 16. C++/CLIでの単純なMEFの例
- 17. 単純なTCPClient/Listner( "hello world")の例
- 18. 単純な例の多態性
- 19. ATMEL SAMB11/BTLC1000単純なGAP/GATTの例
- 20. 単純なsqliteの例ですか?
- 21. 非常に単純なSilverlightファイルアップロードの例
- 22. 単純なプロデューサ - コンシューマの例C#辞書
- 23. 単純なプレーンASP.NETアプリケーションの例(WebフォームとMVCなし)
- 24. 単純なフィードバック制御リソース/例
- 25. Akka.js TestKit:単純な例で、コンパイル・エラー
- 26. は単純に、例えば
- 27. C#単純例外出力
- 28. 単純なTListView OwnerDrawテキストのフォントサイズと色の例?
- 29. 単純な配列の例外の例外
- 30. 単純な例を持つC#.netの内部例外
こんにちは、多分手遅れであり、あなたはすでにあなたの解決策を見つけたが、私は、ネットワーク上のONVIFデバイスを見つけることができるシンプルなC#のコードを持っている、それは非常に簡単です。私はあなたにWCFのソリューションを提供することができますが、私はいくつかの時間が必要です。 –
ねえ、遅すぎることはありません。私はあなたの助けを感謝します:)))それは良い出発点になる可能性があります:)確かに、あなたの時間を取る –