Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 12.0.0 (中文) » QAnywhere » 移动 Web 服务 » 编写移动 Web 服务应用程序

 

设置 Java 移动 Web 服务应用程序

要在 Java 中创建移动 Web 服务应用程序,您就必须完成以下初始化任务。

 ♦  对 Java 初始化 QAnywhere 和移动 Web 服务
  1. 将以下文件的位置添加到类路径中。缺省情况下,这些文件位于 install-dir\Java 下:

    • qaclient.jar
    • iawsrt.jar
    • jaxrpc.jar
  2. 导入 ianywhere.qanywhere.client 和 ianywhere.qanywhere.ws 包:

    import ianywhere.qanywhere.client.*;
    import ianywhere.qanywhere.ws.*;
  3. 创建 QAManager 对象。

    QAManager mgr;
    mgr = QAManagerFactory.getInstance().createQAManager(null);

    还可以为 createQAManager 方法指定属性文件来自定义 QAManager 对象:

    mgr = QAManagerFactory.getInstance().createQAManager("qa_mgr.props.");
    提示

    为了提供最大并发数,多线程应用程序应为每个线程创建一个 QAManager。请参见多线程注意事项

  4. 初始化 QAManager 对象。

    mgr.open(AcknowledgementMode.EXPLICIT_ACKNOWLEDGEMENT);

    open 方法的参数是确认模式,它指示确认消息的方式。它必须为 IMPLICIT_ACKNOWLEDGEMENT 或 EXPLICIT_ACKNOWLEDGEMENT。

    移动 Web 服务所使用的 QAnywhere 消息无法访问移动 Web 服务应用程序。当在 EXPLICIT_ACKNOWLEDGEMENT 模式下使用 QAManager 时,可使用 WSResult 的 Acknowledge 方法来确认包含 Web 服务请求结果的 QAnywhere 消息。此方法指示应用程序是否已经成功地处理了该响应。

    有关确认模式的详细信息,请参见:

    注意

    您可以创建 QATransactionalManager 而非 QAManager。请参见为 Java 客户端实现事务性消息传递

  5. 创建一个服务绑定类的实例。

    移动 Web 服务 WSDL 编译器可从定义 Web 服务的 WSDL 文档生成服务绑定类。

    在发出 Web 服务请求的过程中,QAManager 由 Web 服务绑定类的实例使用来执行消息传送操作。通过设置服务绑定类的 WS_CONNECTOR_ADDRESS 属性,您可指定要用来发送 Web 服务请求(通过 QAnywhere)的连接器地址。使用要连接的 Web 服务 URL 来对每个 QAnywhere Web 服务连接器进行配置。这表示,如果某个应用程序需要位于多个 URL 的 Web 服务,则必须对每个服务 URL 配置 QAnywhere 连接器。

    例如:

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

    注意地址的结尾必须包含 \\。

 另请参见
 示例