首页 > 开发 > Xml > 正文

COM+ Web 服务:通过复选框路由到 XML Web Services (转)5

2020-02-03 14:17:45
字体:
来源:转载
供稿:网友

在图 3 所示的 com+ 应用程序导出向导中,输入代理 .msi 文件的位置和名称。


  1. 在图 3 所示的 com+ 应用程序导出向导中,输入代理 .msi 文件的位置和名称。

    图 3:com+ 应用程序导出向导
  2. 将代理 .msi 文件安装在单独的客户端计算机上,作为预先生成的 com+ 应用程序。
    安装时将对代理进行适当的配置,以便通过 soap 访问正确的服务器和虚拟根。对于客户端激活,可以不使用 wsdl 名字对象,而使用常规非托管的 com+ 激活(例如,cocreateinstancecreateobject 等)。在服务器上创建并在单独的客户端计算机上安装上述 visual basic 计算器示例的应用程序代理后,以下 vbscript 将通过 soap 访问该服务器:
    set c = createobject("vb6soap.calc")for i = 1 to 10 wscript.echo i & " " & c.add(i,i) & " " & timenext 

    如果代理程序没有启用 com+ web 服务,则上述 vbscript 代码将使用 dcom 访问服务器应用程序。

事务性组件示例


简单的计算器远算不上工作量繁重的业务应用程序,因此我们现在考虑带有对象池的适于 com+ 事务性组件的应用程序。
最容易管理和配置的组件是由 servicedcomponent 导出的托管代码组件,如以下 c# 示例所示:
using system;using system.reflection;using system.runtime.interopservices;using system.enterpriseservices;using system.data;using system.data.sqlclient;[assembly: applicationname("sctrans")][assembly: applicationactivation(activationoption.server,    soapvroot="sctrans")][assembly: assemblykeyfile("sctrans.snk")]namespace sctrans{  public interface isctrans  {   string countup (string key);  }  [objectpooling(minpoolsize=0, maxpoolsize=25)]  [justintimeactivation(true)]  [classinterface(classinterfacetype.autodual)]  [transactionattribute(transactionoption.requiresnew)]  public class sctranssqlnc : servicedcomponent, isctrans  {   [autocomplete]   public string countup (string key)   {      _command = new sqlcommand("", _connection);      _command.commandtype = commandtype.text;      _command.connection.open();     _command.commandtext = "update callcount with (rowlock) set       callcount = callcount + 1 where machine='" + key + "'";     _command.executenonquery();      _command.connection.close();     _numcalls++;     return (_numcalls + " nc " + _guid);   }    protected override bool canbepooled()   {     return true;    }   private int _numcalls = 0;   private string _guid = guid.newguid().tostring();   private sqlconnection _connection =    new sqlconnection("user id=myuser;password=my!password;   database=soaptest;server=myserver");   private sqlcommand _command;      }}

图 3:com+ 应用程序导出向导

将代理 .msi 文件安装在单独的客户端计算机上,作为预先生成的 com+ 应用程序。
安装时将对代理进行适当的配置,以便通过 soap 访问正确的服务器和虚拟根。对于客户端激活,可以不使用 wsdl 名字对象,而使用常规非托管的 com+ 激活(例如,cocreateinstance、createobject 等)。在服务器上创建并在单独的客户端计算机上安装上述 visual basic 计算器示例的应用程序代理后,以下 vbscript 将通过 soap 访问该服务器:

set c = createobject("vb6soap.calc")
for i = 1 to 10
wscript.echo i & " " & c.add(i,i) & " " & time
next

如果代理程序没有启用 com+ web 服务,则上述 vbscript 代码将使用 dcom 访问服务器应用程序。

事务性组件示例
简单的计算器远算不上工作量繁重的业务应用程序,因此我们现在考虑带有对象池的适于 com+ 事务性组件的应用程序。

最容易管理和配置的组件是由 servicedcomponent 导出的托管代码组件,如以下 c# 示例所示:

using system;
using system.reflection;
using system.runtime.interopservices;
using system.enterpriseservices;
using system.data;
using system.data.sqlclient;

[assembly: applicationname("sctrans")]
[assembly: applicationactivation(activationoption.server,
   soapvroot="sctrans")]
[assembly: assemblykeyfile("sctrans.snk")]
namespace sctrans
{
  public interface isctrans
  {
   string countup (string key);
  }

  [objectpooling(minpoolsize=0, maxpoolsize=25)]
  [justintimeactivation(true)]
  [classinterface(classinterfacetype.autodual)]
  [transactionattribute(transactionoption.requiresnew)]
  public class sctranssqlnc : servicedcomponent, isctrans
  {
   [autocomplete]
   public string countup (string key)
   {
      _command = new sqlcommand("", _connection);
      _command.commandtype = commandtype.text;
      _command.connection.open();
     _command.commandtext = "update callcount with (rowlock) set
      callcount = callcount + 1 where machine='" + key + "'";
     _command.executenonquery();
      _command.connection.close();
     _numcalls++;
     return (_numcalls + " nc " + _guid);
   }

   protected override bool canbepooled()
   {
     return true;
   }
   private int _numcalls = 0;
   private string _guid = guid.newguid().tostring();
   private sqlconnection _connection =
   new sqlconnection("user id=myuser;password=my!password;
   database=soaptest;server=myserver");
   private sqlcommand _command;
   
  }
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表