Connecting to Genetec Patroller™ Simple Host service - Genetec Patroller™ 6.5

Genetec Patroller™ Simple Host 6.5

Applies to
Genetec Patroller™ 6.5
Last updated
2018-06-18
Language
English
Product
Genetec Patroller™
Version
6.5

To get or push read and hit data through the Simple Host service, you need to connect to a WCF service using your Visual Studio project.

Before you begin

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

  1. Open Visual Studio.
  2. In the Visual Studio Solution Explorer, right-click on the project that references the Simple Host service, then select Add Service Reference.
  3. 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.
  4. 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:
    
    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 Test2008
    {
      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.
          }
      }
    }
                                  
  5. 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:
    
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                      <binding name="BasicHttpBinding_SimpleHost"
                            closeTimeout="00:01:00"
                            openTimeout="00:01:00" 
                            receiveTimeout="00:10:00" 
                            sendTimeout="00:01:00"
                            allowCookies="false" 
                            bypassProxyOnLocal="false"
                            hostNameComparisonMode="StrongWildcard"
                            maxBufferSize="65536" 
                            maxBufferPoolSize="524288"
                            maxReceivedMessageSize="65536"
                            messageEncoding="Text" 
                            textEncoding="utf-8" 
                            transfer Mode="Buffered"
                            useDefaultWebProxy="true">
                          <readerQuotas maxDepth="32" 
                                       maxStringContentLength="8192"
                                       maxArrayLength="16384" 
                                       maxBytesPerRead="4096"
                                       maxNameTableCharCount="16384" />
                          <security mode="None">
                              <transport clientCredentialType="None" 
                                          proxyCredentialType="None"
                                          realm="" />
                              <message clientCredentialType="UserName" 
                                          algorithmSuite="Default" />
                           </security>
                      </binding>
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost:8001/SimpleHost/" 
                     binding="basicHttpBinding" 
                     bindingConfiguration="BasicHttpBinding_SimpleHost"
                     contract="AutoVu.SimpleHost.Service.SimpleHost"
                     name="BasicHttpBinding_SimpleHost" />
            </client>
       </system.serviceModel>
    </configuration                                        
                                  
  6. Replace the readerQuotas tag with the following, and then save the project file.
    The default configuration does not allow a large amount of data to be transferred in one message, which we need when we transfer the images.
    
    <readerQuotas maxDepth="2147483647"
                  maxStringContentLength="2147483647"
                  maxArrayLength="2147483647"
                  maxBytesPerRead="2147483647"
                  maxNameTableCharCount="2147483647" />      
                           
  7. Compile and run the project

Results

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:

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();
   }
}