| | english | español | français |
  Home|Resources|BCH Interoperability Services 3.0|Quick Start - Querying the BCH for documents   Printer-friendly version

Quick Start - Querying the BCH for documents

C#

using System;
using MyNamespace.org.biodiv.bch; // Imported Web Reference

namespace MyNamespace
{
    class MyClass
    {
        static void Main(string[] args)
        {
            try
            {
                // Load Query to Xml String
                // Sample query loading all records of a country
                string sQueryXml = "";
                sQueryXml += "<query>";
                sQueryXml += " <conditions>";
                sQueryXml += "  <relates property=\"government\" refID=\"ca\" />";
                sQueryXml += " </conditions>";
                sQueryXml += "</query>";

                // Initialize WebService
                BCHWebService30 oWebService = new BCHWebService30();
            
                // Call SOAP Method
                string sDocumentsXml = oWebService.query(sQueryXml);

                Console.WriteLine("Query result documents: {0}", sDocumentsXml );
            }
            catch(Exception e)
            {
                // Output error message to console
                Console.WriteLine(e.Message);
            }
        }
    }
}

VB.NET

Imports System
Imports MyNamespace.org.biodiv.bch ' Imported Web Reference

Module MyModule
    Sub Main()
        Try

            ' Load Query to Xml String
            ' Sample query loading all records of a country
            Dim sQueryXml As String
            sQueryXml &= "<query>"
            sQueryXml &= " <conditions>"
            sQueryXml &= "  <relates property=""government"" refID=""ca"" />"
            sQueryXml &= " </conditions>"
            sQueryXml &= "</query>"

            ' Initialize WebService
            Dim oWebService As New BCHWebService30()

            ' Call SOAP Method
            Dim sDocumentsXml As String
            sDocumentsXml= oWebService.query(sQueryXml )

            Console.WriteLine("Query result documents: {0}", sDocumentsXml)

        Catch e As Exception
            ' Output error message to console
            Console.WriteLine(e.Message)
        End Try
    End Sub
End Module

Java (J2SE 6 Update 1, Apache Axis 1.4)

import org.biodiv.bch.service._3_0.*; // Stub generated using WSDL2Java

public class MyClass 
{
    public static void main(String[] args) 
    {
        try 
        {
            // Load Query to Xml String
            // Sample query loading all records of a country
            String sQueryXml = "";
            sQueryXml += "<query>";
            sQueryXml += " <conditions>";
            sQueryXml += "  <relates property=\"government\" refID=\"ca\" />";
            sQueryXml += " </conditions>";
            sQueryXml += "</query>";

            // Initialize WebService
            BCH_x0020_Web_x0020_Service_x0020_30Locator oLocator = new BCH_x0020_Web_x0020_Service_x0020_30Locator();
            BCH_x0020_Web_x0020_Service_x0020_30Soap oWebService = oLocator.getBCH_x0020_Web_x0020_Service_x0020_30Soap(); 
                        
            // Call SOAP Method
            String sDocumentsXml = oWebService.query(sQueryXml);

            System.out.println("Query result documents: " + sDocumentsXml);
        }
        catch(Exception e) 
        {
            // Output error message to console
            System.out.println(e.getMessage());
        }
    }
}

Generating BCH Web Service Stub using WSDL2Java

VBScript

On Error Resume Next

' Load Query to Xml String
' Sample query loading all records of a country
Dim sQueryXml 
sQueryXml = sQueryXml & "<query>"
sQueryXml = sQueryXml & " <conditions>"
sQueryXml = sQueryXml & "  <relates property=""government"" refID=""ca"" />"
sQueryXml = sQueryXml & " </conditions>"
sQueryXml = sQueryXml & "</query>"

' Initialize WebService
Dim oWebService 
Set oWebService = CreateObject("MSSOAP.SoapClient")

If Err = 0 Then oWebService.mssoapinit "http://bch.biodiv.org/service/3.0/service.asmx?WSDL"

' Call SOAP Method
Dim sDocumentsXml 
If Err = 0 Then sDocumentsXml = oWebService.query(sQueryXml)

If Err = 0 Then
    WScript.Echo "Query result documents: " & sDocumentsXml
Else
    ' Output error message to console
    WScript.Echo Err.Description

    On Error Goto 0
End If

Python 2.4.4 (SOAPpy 0.12.0)

# -*- coding: UTF-8 -*-
import sys
from SOAPpy import SOAPProxy, SOAPConfig

try:

    # Load Query to Xml String
    # Sample query loading all records of a country
    sQueryXml  = u""
    sQueryXml += u"<query>"
    sQueryXml += u" <conditions>"
    sQueryXml += u"  <relates property=\"government\" refID=\"ca\" />"
    sQueryXml += u" </conditions>"
    sQueryXml += u"</query>"

    # Initialize WebService
    config = SOAPConfig()
    config.buildWithNamespacePrefix = 0 # .NET compatibility
    
    ep = "http://bch.biodiv.org/service/3.0/service.asmx" # endpoint
    ns = "http://bch.biodiv.org/service/3.0" # namespace
    sa = "http://bch.biodiv.org/service/3.0/query" # soapaction

    oWebService = SOAPProxy(ep, namespace=ns, soapaction=sa, config=config)
    
    # Call SOAP Method
    sDocumentsXml= oWebService.query(query=sQueryXml)

    print "Query result documents: " + sDocumentsXml
    
except:
    # Output error message to console
    print sys.exc_info()[1]

Perl 5.8.8 (SOAP-Lite 0.69)

use SOAP::Lite;

# Load Query to Xml String
# Sample query loading all records of a country
$QueryXml = "";
$QueryXml = $QueryXml . "<query>";
$QueryXml = $QueryXml . " <conditions>";
$QueryXml = $QueryXml . "  <relates property=\"government\" refID=\"ca\" />";
$QueryXml = $QueryXml . " </conditions>";
$QueryXml = $QueryXml . "</query>";


# Initialize WebService
$ep = "http://bch.biodiv.org/service/3.0/service.asmx"# endpoint
$ns = "http://bch.biodiv.org/service/3.0"# namespace
$sa = "query"# action

$webService = SOAP::Lite
    -> uri($ns) 
    -> on_action( sub { join "/", $ns, $_[1] } ) # ASP.NET WebService compatibility
    -> proxy($ep);

$method = SOAP::Data->name($sa)->attr( { xmlns => $ns } );

@params = (SOAP::Data->name(query => SOAP::Data->type(string => $QueryXml )));

# Call SOAP Method
$result = $webService->call($method, @params);

unless ($result->fault) 

    print "Query result documents: ", $result->result();
}
else

    # Output error message to console
    print $result->faultcode, " - ",  $result->faultstring; 
}

   
   
Update on 2007-11-21
United Nations Environment Programme United Nations