.net WCF-是否可以远程创建对象?怎样?
当带有某个WCF服务的主机进程正在运行时-一切正常。 但当托管进程未运行时,WCF无法创建对象并使用它 换句话说,我有一个名为“ScrnSrvcR2.exe”的进程,它承载着通过WCF公开的“ScreensApi”对象。 所以,当“ScrnSrvcR2.exe”进程运行WCF时,客户端可以连接并使用“ScreensApi”对象。但当“ScrnSrvcR2.exe”进程未运行时-客户端无法连接 问题是,是否可以通过第一个创建“ScreensApi”对象的请求使远程系统(也包括作为远程系统特殊情况的localhost)自动启动该托管进程 因此,在这种情况下,我希望从WCF获得某种DCOM风格的功能,远程系统可以调用CreateRemoteComObject函数,并且对象宿主进程将自动启动,并提供对象的实例 有可能用WCF来做吗? 怎么做 下面是我用来创建WCF对象的一段代码,仅供参考:.net WCF-是否可以远程创建对象?怎样?,.net,wcf,autostart,.net,Wcf,Autostart,当带有某个WCF服务的主机进程正在运行时-一切正常。 但当托管进程未运行时,WCF无法创建对象并使用它 换句话说,我有一个名为“ScrnSrvcR2.exe”的进程,它承载着通过WCF公开的“ScreensApi”对象。 所以,当“ScrnSrvcR2.exe”进程运行WCF时,客户端可以连接并使用“ScreensApi”对象。但当“ScrnSrvcR2.exe”进程未运行时-客户端无法连接 问题是,是否可以通过第一个创建“ScreensApi”对象的请求使远程系统(也包括作为远程系统特殊情况的
// this code works fine when "ScrnSrvcR2.exe" is running
protected void InitializeScreens()
{
string endPointAddr = null;
string transport = "net.tcp://";
string hostAddress = "localhost";
string servicePath = "ScreensApi";
// [... optional reading of transport, hostAddress, servicePath values skipped... ]
if (string.IsNullOrEmpty(endPointAddr))
endPointAddr = transport + hostAddress + "/" + servicePath;
System.ServiceModel.Channels.Binding bnd = null;
NetTcpBinding tcpBinding = new NetTcpBinding();
bnd = tcpBinding;
tcpBinding.Name = "epNetTcp"; // this name is defined in config file
EndpointAddress endpointAddress = new EndpointAddress(endPointAddr);
bool isGoodProxy = false;
try
{
try
{
this.ScreensProxy = new ScreensApiClient(bnd, endpointAddress);
string un = null, pw = null;
// [... optional reading of login/password skipped...]
if (!string.IsNullOrEmpty(un) && !string.IsNullOrEmpty(pw))
{
ToLogger(TraceLevel.Verbose, string.Format("Station[ {0} ].Screens => Use credentials: {1}, {2}", this.Name, un, pw));
this.ScreensProxy.ClientCredentials.UserName.UserName = un;
this.ScreensProxy.ClientCredentials.UserName.Password = pw;
}
un = null; pw = null;
// [... optional reading of login/password skipped...]
if (!string.IsNullOrEmpty(un) && !string.IsNullOrEmpty(pw))
{
ToLogger(TraceLevel.Verbose, string.Format("Station[ {0} ].Screens => Use Windows-credentials: {1}, {2}", this.Name, un, pw));
this.ScreensProxy.ClientCredentials.Windows.ClientCredential.UserName = un;
this.ScreensProxy.ClientCredentials.Windows.ClientCredential.Password = pw;
}
this.ScreensProxy.Open();
this.ScreensProxy.Ping(); // note: Ping() is a method of ScreensApi object, just to check if it is alive
this.ScreensStationDescriptor = this.ScreensProxy.CreateStationDescriptor(this.Owner.Name, this.Name, CommonUtils.HostInfoStamp());
this.ScreensProxy.InitializeStation(this.ScreensStationDescriptor);
this.ScreensRuntimeContext = this.ScreensProxy.GetStationContext(this.ScreensStationDescriptor);
isGoodProxy = true;
}
catch (Exception exc)
{
ToLogger(TraceLevel.Error, string.Format("Station[ {0} ].Screens -> {1}\n at {2}", this.Name, ErrorUtils.FormatErrorMsg(exc), exc.StackTrace));
throw;
}
}
finally
{
if (!isGoodProxy)
{
this.ScreensProxy = null;
this.ScreensStationDescriptor = null;
this.ScreensRuntimeContext = null;
ToLogger(TraceLevel.Warning, string.Format("Station[ {0} ].Screens -> Remove ScreensProxy object ref as invalid!", this.Name));
}
}
}
我可能需要在代码中添加什么,使其自动启动WCF对象托管过程
提前谢谢。您考虑过在IIS中托管吗?WCF不是远程对象管理器或类似的东西-它只是一个基于XML可序列化数据OK的消息传递系统。您能推荐一些.NET域中的远程对象管理器吗?