Setting up .NET mobile web service applications

Before using .NET with QAnywhere, you must make the following changes to your Visual Studio project:

  • Add references to the QAnywhere .NET DLL and the mobile web services .NET DLL. This tells Visual Studio which DLL to include to find the code for the QAnywhere .NET API and the mobile web services .NET API.
  • Add lines to your source code to reference the QAnywhere .NET API classes and the mobile web services .NET API classes. In order to use the QAnywhere .NET API, you must add a line to your source code to reference the data provider. You must add a different line for C# than for Visual Basic.

Complete instructions follow.

To add references to the QAnywhere .NET API and mobile web services API in a Visual Studio .NET project

  1. Start Visual Studio and open your project.

  2. In the Solution Explorer window, right-click the References folder and choose Add Reference.

  3. On the .NET tab, click Browse to locate iAnywhere.QAnywhere.Client.dll and iAnywhere.QAnywhere.WS.dll. The location of these files is (relative to your SQL Anywhere installation directory):

    • .NET Framework 2.0: \Assembly\v2
    • .NET Compact Framework 2.0: ce\Assembly\v2

    From the appropriate directory for your environment, select each DLL and click Open.

  4. To verify that the DLLs are added to your project, open the Add Reference window and open the .NET tab. iAnywhere.QAnywhere.Client.dll and iAnywhere.QAnywhere.WS.dll appear in the Selected Components list. Click OK.

Referencing the data provider classes in your source code

To reference the QAnywhere .NET API and mobile web services API classes in your code

  1. Start Visual Studio and open your project.

  2. If you are using C#, add the following lines to the list of using directives at the beginning of your file:

    using iAnywhere.QAnywhere.Client;
    using iAnywhere.QAnywhere.WS;
  3. If you are using Visual Basic, add the following lines to the list of imports at the beginning of your file:

    Imports iAnywhere.QAnywhere.Client
    Imports iAnywhere.QAnywhere.WS

    The Imports lines are not strictly required. However, they allow you to use short forms for the QAnywhere and mobile web services classes. Without them, you can still use the fully qualified class name in your code. For example, the following code uses the long form:

    iAnywhere.QAnywhere.Client.QAManager 
    mgr = 
     new iAnywhere.QAnywhere.Client.QAManagerFactory.Instance.CreateQAManager(
    "qa_manager.props" );

    The following code uses the short forms:

    QAManager mgr = QAManagerFactory.Instance.CreateQAManager(
     "qa_manager.props" );

To initialize QAnywhere and mobile web services for .NET

  1. Include the iAnywhere.QAnywhere.Client and iAnywhere.QAnywhere.WS namespaces, as described in the previous procedure.

    using iAnywhere.QAnywhere.Client;
    using iAnywhere.QAnywhere.WS;
  2. Create a QAManager object.

    For example, to create a default QAManager object, invoke CreateQAManager with null as its parameter:

    QAManager mgr;
    mgr = QAManagerFactory.Instance.CreateQAManager( null );
    Tip

    For maximum concurrency benefits, multi-threaded applications should create a QAManager for each thread. See Multi-threading considerations.

    For more information about QAManagerFactory, see QAManagerFactory class.

    Alternatively, you can create a QAManager object that is customized using a properties file. The properties file is specified in the CreateQAManager method:

    mgr = QAManagerFactory.Instance.CreateQAManager( 
      "qa_mgr.props" );

    where qa_mgr.props is the name of the properties file that resides on the remote device.

  3. Initialize the QAManager object. For example:

    mgr.Open(
       AcknowledgementMode.EXPLICIT_ACKNOWLEDGEMENT);

    The argument to the open method is an acknowledgement mode, which indicates how messages are to be acknowledged. It must be one of IMPLICIT_ACKNOWLEDGEMENT or EXPLICIT_ACKNOWLEDGEMENT.

    QAnywhere messages used by mobile web services are not accessible to the mobile web services application. When using a QAManager in EXPLICIT_ACKNOWLEDGEMENT mode, use the Acknowledge method of WSResult to acknowledge the QAnywhere message that contains the result of a web services request. This method indicates that the application has successfully processed the response.

    For more information about acknowledgement modes, see:

    Note

    Instead of creating a QAManager, you can create a QATransactionalManager. See Implementing transactional messaging for .NET clients.

  4. Create an instance of the service binding class.

    The mobile web services WSDL compiler generates the service binding class from the WSDL document that defines the web service.

    The QAManager is used by the instance of the web service binding class to perform messaging operations in the process of making web service requests. You specify the connector address to use to send web service requests through QAnywhere by setting the property WS_CONNECTOR_ADDRESS of the service binding class. You configure each QAnywhere web service connector with the URL of a web service to connect to, and if an application needs web services located at more than one URL, configure the connector for each URL.

    For example:

    CurrencyConverterSoap service = new CurrencyConverterSoap( )
    service.SetQAManager(mgr);
    service.setProperty(
       "WS_CONNECTOR_ADDRESS",
       "ianywhere.connector.currencyconvertor\\");

    Note that the final \\ in the address must be included.

See also
Example

To initialize mobile web services, you must create a QAManager and create an instance of the service binding class. For example:

// QAnywhere initialization
  QAManager mgr = QAManagerFactory.Instance.CreateQAManager( null );
  mgr.SetProperty( "CONNECT_PARAMS", "eng=qanywhere;dbf=qanywhere.db;uid=ml_qa_user;pwd=qanywhere" );
  mgr.Open( AcknowledgementMode.IMPLICIT_ACKNOWLEDGEMENT );
  mgr.Start();
  
  // Instantiate the web service proxy
  CurrencyConvertorSoap service = new CurrencyConvertorSoap();
  service.SetQAManager( mgr );
  service.SetProperty( "WS_CONNECTOR_ADDRESS", "ianywhere.connector.currencyconvertor\\" );

The response time for the CurrencyConvertor sample depends on the availability of the web service. Asynchronous web service requests are useful when the mobile web service application is not always available. With this method, a web service request is made by calling a method on the service binding class to place the request in an outgoing queue. The method returns a WSResult, which can be used to query the status of the response at a later time, even after the application has been restarted. See Asynchronous web service requests.