您的位置:程序门 -> .net技术 -> c#



c#如何连接远程com+组件服务,以及连接时身份验证问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


c#如何连接远程com+组件服务,以及连接时身份验证问题
发表于:2007-03-31 10:54:10 楼主
我用c#写了一个客户端程序,想连接远程的com+组件服务,不知到如何连,那位高人可以给我一些帮助呢?

原来在c++里面调用com+组件,如下:

coauthidentity   us;
us.user                       =user;
us.userlength           =   wcslen(us.user);
us.password               =   password;
us.passwordlength   =   wcslen(us.password);
us.domain=null;
us.domainlength=0;
us.flags                     =   sec_winnt_auth_identity_unicode;

coauthinfo   auth;
auth.dwauthnsvc                       =   rpc_c_authn_winnt;
auth.dwauthzsvc                       =   rpc_c_authz_none;
auth.pwszserverprincname     =   null;
auth.dwauthnlevel                   =   pc_c_authz_none;
auth.dwimpersonationlevel   =   rpc_c_imp_level_impersonate;
auth.dwcapabilities               =   eoac_none;
auth.pauthidentitydata         =   &us;

serverinfo.pauthinfo=&auth;
multi_qi   multiqi={&iid_iunknown,null,noerror};
hr=cocreateinstanceex(clsid_dacomsta,null,clsctx_remote_server,&serverinfo,1,&multiqi);

用两个结构体分别传入了用户名,密码,表明为集成windows身份验证,另外一个传入了远程电脑中com+服务的配置,这样将这些信息统一传送给cocreateinstanceex才创建的对象

在c#中,如何将这些信息传送给对方呢,我查了很多资料,但还是没有找到,有说用   activator.createinstance的,但只成功调用了本地com,也有提示说在自动生成的   assemblyinfo.cs   文件中添加
[assembly:   applicationaccesscontrol
        (
                accesscheckslevel   =   accesschecksleveloption.applicationcomponent,
                authentication   =   authenticationoption.none,
                impersonationlevel   =   impersonationleveloption.impersonate
        )
]
这个,只提供了相应服务的配置,但如何将用户名,密码传送给创建函数?(集成windows身份验证)我一直没有查到,希望各位大侠能帮我度此难关啊!!!

非常感谢大家的帮助!
发表于:2007-03-31 11:28:281楼 得分:0
用序列化、remoting试试。具体的可以看看msdn。
发表于:2007-03-31 11:42:102楼 得分:0
楼上方法应该可以。   有情帮顶~~~~~
发表于:2007-03-31 12:58:353楼 得分:0
能否具体一些呢,我查了很多msdn的文章了,都是很笼统的啊,真是好办啊,不过还是感谢以上高人的指点...
发表于:2007-03-31 13:01:444楼 得分:0
友情up..
发表于:2007-03-31 22:29:025楼 得分:0
请大家多多关注,谢谢!
发表于:2007-03-31 22:39:436楼 得分:0
等待星级的专家来回贴吧。
发表于:2007-04-01 01:17:497楼 得分:0
顶!
发表于:2007-04-01 09:09:108楼 得分:0
up
发表于:2007-04-01 09:46:289楼 得分:0
1、远程对象(实现你要在客户端调用的业务逻辑),远程对象必须继承system.marshalbyrefobject类或其子类。

using   system;

namespace   wrox.professionalcsharp
{
///   <summary>
///   summary   description   for   class1.
///   </summary>
public   class   hello   :   system.marshalbyrefobject
{
public   hello()
{
console.writeline( "constructor   called ");
}

~hello()
{
console.writeline( "destructor   called ");
}

public   string   greeting(string   name)
{
console.writeline( "greeting   called ");
return   "hello,   "   +   name;
}
}
}

2、服务器:作为远程对象的宿主程序,注册tcp通道,注册远程对象。

using   system;
using   system.runtime.remoting;
using   system.runtime.remoting.channels;
using   system.runtime.remoting.channels.tcp;
using   system.runtime.remoting.channels.http;

using   system.collections.specialized;

namespace   wrox.professionalcsharp
{
///   <summary>
///   summary   description   for   class1.
///   </summary>
class   helloserver
{
          public   static   void   main(string[]   args)
{
               
                  tcpserverchannel   tcpchannel   =   new   tcpserverchannel(properties,   sinkprovider);
  channelservices.registerchannel(tcpchannel);
    remotingconfiguration.registerwellknownservicetype(
typeof   (wrox.professionalcsharp.hello),   //   type
"hi ", //   uri
wellknownobjectmode.singlecall); //   mode

system.console.writeline( "hit   to   exit ");
system.console.readline();
}

}
}

3、客户端:注册tcp通道,注册远程对象,创建、调用远程对象

using   system;
using   system.runtime.remoting;
using   system.runtime.remoting.channels;
using   system.runtime.remoting.channels.tcp;
using   system.runtime.remoting.channels.http;

namespace   wrox.professionalcsharp
{
///   <summary>
///   summary   description   for   class1.
///   </summary>
class   helloclient
{
static   void   main(string[]   args)
{
channelservices.registerchannel(new   tcpclientchannel());

remotingconfiguration.registerwellknownclienttype(
typeof(wrox.professionalcsharp.hello),  
"tcp://localhost:8086/hi ");
hello   obj   =   new   hello();
if   (obj   ==   null)
{
console.writeline( "could   not   locate   server ");
return;
}

for   (int   i=0;   i <   5;   i++)
{
console.writeline(obj.greeting( "christian "));
}
}
}
}
发表于:2007-04-01 10:18:4610楼 得分:0
关注,学习。。。。。
发表于:2007-04-01 11:14:5711楼 得分:0
在此非常感谢hertcloud(·£孙子兵法£·)   的帮助,你说得非常详细,非常感谢,但有一个问题,因为我只负责客户端,服务器端是其它企业的服务,就是标准的com+服务,就是mts,不能做任何改动的,那这样的情况下客户端如何用.net调用其服务呢?.net好像可以与创建远程对象,但关键是如何做身份验证的问题?
发表于:2007-04-01 16:30:0212楼 得分:0
顶!
发表于:2007-04-01 17:29:3813楼 得分:0
可不可以改为远程提供一个service接口.
发表于:2007-04-07 13:08:0214楼 得分:0
up


快速检索

最新资讯
热门点击