Open Genetec Patroller™ Config Tool to activate the
service.
What you should know
In this procedure, you will use Microsoft Visual Studio 2013 to automatically
generate code to connect to a WCF service. There is no need to use an existing AutoVu DLL.
Procedure
Open Visual Studio.
In the Visual Studio Solution Explorer, right-click on
the project that references the Simple Host service, then select Add
Service Reference.
In the Address field, enter the URL of the Simple Host
service. Click Go.
If the Simple Host service is running on the same computer, the address is:
http://localhost:8001/SimpleHost
If the Simple Host service is running, the Simple Host web service will
appear in the Services box. You can expand it to see the functions it contains.
Enter a namespace for the auto-generated code that is more descriptive than its
default ServiceReference1, then click OK.
In the following example, we use the name AutoVu.SimpleHost.Service.
New auto-generated code will be added to your project. The following
example code shows how to use the service from within a class of your
application:
Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
namespace Test2020
{
public partial class Form1 : Form
{
AutoVu.SimpleHost.Service.SimpleHostClient _simpleHost;
public Form1()
{
InitializeComponent();
}
private void buttonGetHit_Click(object sender, EventArgs e)
{
string lXml;
try
{
lXml = _simpleHost.GetHitData
(new Guid("48E6B5C7-0347-470F-9A95-9650AA7EB568"));
}
catch (Exception e1)
{
Console.WriteLine(e1.Message);
return;
}
}
private void buttonInit_Click(object sender, EventArgs e)
{
_simpleHost =
new AutoVu.SimpleHost.Service.SimpleHostClient
("BasicHttpBinding_SimpleHost");
// the string passed to the constructor is the name of
// the configuration that was generated in the
// App.config file.
}
}
}
In your project or the main project of the application, find the
App.config file.
NOTE: The App.config file must be the one in the Startup project of
the solution, otherwise the configuration will not apply.
The autogenerating code process should have added a
system.serviceModel tag to the content of the file:
The string received from the Simple Host is XML compliant and can be analysed using
the .NET XmlDocument class. Also the images need to be re-encoded as a byte[] to create
a bitmap object. See the following code:
Code
private void ButtonGetHit_Click(object sender, EventArgs e)
{
string lXml;
XmlDocument lDoc = new XmlDocument();
lXml = _simpleHost.GetHitData
(new Guid("4E6B5C7-0347-470F-9A95-9650AA7EB568"));
lDoc.LoadXml(lXml);
XmlNodeList listXmlImages =
lDoc.SelectNodes(string.Format("{0}/{1}/{2}/{3}",
"AutoVuReturn","Hit", "Vehicle","Image"));
foreach (XmlNode node in listXmlImages)
{
XmlNode purposeNode = node.SelectSingleNode("Purpose");
XmlNode dataNode = node.SelectSingleNode("Data");
byte[] imageData = Covert.FromBase64String(dataNode.InnerXml);
MemoryStream lMemoryStream = new MemoryStream(imageData);
Bitmap image = new Bitmap(lMemoryStream);
switch (purposeNode.InnerXml)
{
case "LPR":
image.Save("Image_LPR.jpg");
break;
case "Context":
image.Save("Image_Context.jpg");
break;
}
image.Dispose();
}
}