Remoting from IIS Hosted component to ASP.NET Client application

省级产业研发综合指标数据2004-2024年 01、数据介绍 产业研发综合指标通常用于衡量各省份在科技创新、研发投入、成果转化及产业发展等方面的综合实力。结合现有的权威评估报告与统计整理如下数据。包括研发机构情况,R&D相关投入,新产品开发与销售、发明专利数、技术引进技术改造经费支出等数据。 数据名称:省级产业研发综合指标数据 数据年份:2004-2024年 02、数据指标 统计年度 地区代码 地区名称 研发机构数(个) R&D人员折合全时当量(人年) R&D经费内部支出(万元) R&D项目数(项) R&D项目经费(万元) 新产品开发项目数(项) 新产品开发经费支出(万元) 新产品销售收入(万元) 新产品销售收入-出口(万元) 专利申请数(件) 发明专利申请数(件) 有效发明专利数(件) 技术改造经费支出(万元) 购买境内技术经费支出(万元) 技术引进经费支出(万元) 消化吸收经费支出(万元) 立即下载

Introduction

This walkthrough will show how to set up a simple component on IIS and access it through an ASP.NET webapp. Please refer to other articles to get background information on remoting. The goal of this project is to:

  1. Make a remote service hosted on IIS that authenticates users
  2. Make wrapper classes to abstract the remoting "fabric" to the client
  3. Set up an ASP.NET web application to consume the remote service through the wrapper assembly

No demo project is provided here because you'll have to do some setup with IIS an so forth yourselves. I didn't get this subject myself before I actually struggled with it on my own. So the intent here is to guide you through the process.

Background

There are a lot of literature on .NET remoting out there. Ingo Rammer's book "Advanced .NET Remoting" is told to be great and his website (www.dotnetremoting.cc) for sure are. Other sources for this subject can be somewhat complex from time-to-time because they often are written by experienced COM/DCOM programmers. For me it seemed as they made it more difficult than it is. This is why I made this simple straight-forward walkthrough to get remoting up and running in a known environment for ASP.NET programmers. Here is my blog from yesterday with some more background.

First off: Define your service

Before you start coding, decide what your service is supposed to do, because you're going to make an interface. The interface will be built in a separate assembly (DLL) and deployed with both client and server application, so they have a common ground. My service, in this case, is supposed to authenticate users so I'll define my interface like this:

Collapse code snippet
public interface IAuthenticationService
{
string Authenticate(string username, string password);
}

The interface takes username/password as parameters and returns an encrypted FormsAuthenticationTicket (as String) that the ASP.NET application will use for creating a cookie for the authenticated user.

Secondly: The server application

To be able to run a class as a .NET remoting service you have to make a class that inherits MarshalByRefOBject. We also want the class to implement the IAuthenticationService interface defined above, so the client can use it.

Collapse
public class AuthenticationService : MarshalByRefObject, 
IAuthenticationService
{
private IUserDAO UserDAO;

public AuthenticationService()
{
// Get an instance of our User Data Access Object

UserDAO = (IUserDAO)ServiceLocator.Instance.
DataAccessObjectGet(StorageTypes.SqlServer,
Services.UserService);
}


public string Authenticate(string username, string password)
{
UserItem user;
try
{
// Get the user from the datastore and validate password

user = UserDAO.UserByEmailGet(username);
if(!(user.Password.CompareTo(password) == 0))
return "";
}
catch(eFactory.Data.NoDataFoundException)
{
// User Not found

return "";
}

// Create Userdata - omitted for clarity

return encryptedTicket;
}
}

Piece of cake. Inherit MarshalByRefObject (from System.Runtime.Remoting) and implement the interface we made earlier. In this example I use a singleton ServiceLocator class to delver an instance of a data access object for the data-service, UserService. Then this service (UserDAO) is used to fetch the user object that contains the password.

Now we can compile our server component and deploy our service to IIS. If you have IIS installed the simplest thing to do is:

  1. Create a new virtual folder on IIS (through inetmgr.exe) that points to the directory containing our server project. Beware that the name you provide for the folder also will be the application name in IIS.

    You might experience some trouble with setting up the virtual folder on IIS. One hint is that all parent directories of the one you assign as a virtual IIS folder must allow the ASPNET user to read, execute and list. Otherwise consult MSDN for advice on setting up virtual folders.

  2. Make sure that the DLL is placed directly under the /bin folder (not in /bin/debug!)
  3. Create a Web.Config file in the root of the virtual folder (our project folder). This Web.config file needs to hold the remoting settings (deployment description). Additionally you'd probably want to include some database connection strings and so forth if you are doing lookups in your authenticate method. The server web.config looks like this:
    Collapse
    <configuration>
    <system.runtime.remoting>
    <application>
    <service>
    <wellknown
    mode="SingleCall"
    type="CodeProject.AuthenticationService,
    AuthenticationServiceComponent"

    objectUri="AuthenticationService.soap" />
    </service>
    <channels>
    <channel
    name="TheChannel"
    priority="100"
    ref="http" />
    </channels>
    </application>
    </system.runtime.remoting>
    <appSettings>
    <add key="SqlServer" value="connstring"/>
    </appSettings>
    </configuration>

The remoting part of the config file is contained by the <system.runtime.remoting> tags. The application element inside is set up automatically by ASP.NET and IIS so we don't have to specify any attributes (specifying the name attribute would conflict because the name of our application is already set to be the same as the name of the virtual directory).

Then we specify our services. ASP.NET only supports well-known services (not client-activated) so we don't have to think much about that. The really important thing here is the type attribute. The first parameter here is the fully qualified class name of our service. My AuthenticationService class was compiled in the namespace CodeProject as you can see. The second parameter in the type attribute is the name of the DLL file. This file resides in the /bin directory of the IIS virtual folder and contains the class CodeProject.AuthenticationService. The third attribute is objectUri and defines a URI for our service. Just set it to [classname.soap] for now.

What's left here is to define a channel for IIS to use for this service. We'll give it a name, TheChannel, set a priority flag and make a reference to the pre-defined "HTTP" channel in machine.config.

Finally I had to add my database connection string:)

Now you should be able to check out your service by entering it's URL and get the WSDL. like this:

http://hostname/VirtualFolderName/objectUri?wsdl in my case: http://localhost/AuthenticationRemotingService/AuthenticationService.soap?wsdl.

Really cool isn't it?

Next lets make the client! Or not yet?

I found it convenient to wrap all remoting code in a supporting assembly to catch remoting errors and such. Because others (other coders) that are going to use this service have to import my Interface assembly anyways, it won't hurt to supply some wrappers.

I chose to make a singleton class to front my service. The only thing it does is to get the remote object and call on the authenticate service and return it's value as a HttpCookie. If something goes wrong it catches the exception. It also hides some semi-nasty implementation code to be able to instantiate an object of our interface type without having to hardcode the URL. I did a slight rewrite of Ingo Rammers RemotingHelper class, converting it to a singleton to accomplish this.

This is the LoginHandler wrapper class:

Collapse
public sealed class LoginHandler
{
public static readonly LoginHandler Instance = new LoginHandler();

private LoginHandler(){}

public HttpCookie DoLogin(string username, string password)
{
try
{
IAuthenticationService auth =
(IAuthenticationService)RemotingHelper.Instance.GetObject
(typeof(IAuthenticationService));
}
catch(System.Runtime.Remoting.RemotingException ex)
{
//do some logging

return "";
}

string ticket = auth.Authenticate(username, password);
if(ticket == "")
return null;
else
return new System.Web.HttpCookie(FormsAuthentication.
FormsCookieName, ticket);

}
}

The rewrite of Ingo Rammer's class:

Collapse
internal sealed class RemotingHelper 
{
public static readonly RemotingHelper Instance =
new RemotingHelper();

private IDictionary wellKnownTypes;

private RemotingHelper()
{
wellKnownTypes = new Hashtable();
foreach (WellKnownClientTypeEntry entr in
RemotingConfiguration.GetRegisteredWellKnownClientTypes())
{
if (entr.ObjectType == null)
{
throw new RemotingException("A configured
type could not be found. Please check spelling"
);
}
wellKnownTypes.Add (entr.ObjectType,entr);
}
}

public Object GetObject(Type type)
{
WellKnownClientTypeEntry entr =
(WellKnownClientTypeEntry)wellKnownTypes[type];
if(entr == null)
{
throw new RemotingException("Type not found!");
}
return Activator.GetObject(entr.ObjectType,entr.ObjectUrl);
}
}

When instantiated this class reads all available well-known types from the registered types collection in the RemotingConfiguration. It then compares the class name you provide in GetObject to the well-known types. Without this class, you'd have to hardcode the service server URL or get this from the config file.

Off to the ASP.NET client webapp!

Now its playtime. All the hard work is nearly done. Finish off by:

  1. Create a new ASP.NET web application.
  2. Add references to the Wrapper-, and Interface assemblies.
  3. Open the client application web.config file.

    You will need to let your client application know where to find the implementation of the interface defined in the assembly you just added. It's the implementation of this interface we will "remote". Just like for the server config file you have to place a system.runtime.remoting element as a sub-element to <configuration> Its done like this:

    Collapse
    <system.runtime.remoting>
    <application>
    <client url="http:/localhost/YourIISVirtualFolderName
    /AuthenticationService"
    >
    <wellknown
    type="CodeProject.IAuthenticationService,
    RemotingInterfacesComponent"

    url="http://localhost/YourIISVirtualFolderName/
    AuthenticationService.soap"
    />
    </client>
    </application>
    </system.runtime.remoting>

    The URL of the client element is the address of your virtual folder on IIS that you defined for your server component. Then we define a well-known type which is describing the fully qualified name for the interface we made first off in this walkthrough, and the second parameter is (like in the server config) the name of the DLL containing this interface. This DLL must of course be available and referenced by our ASP.NET client web app. The last parameter is the URL to the service + the objectUri that we defined in the server web.config file. We don't need to set up any channels here. IIS will handle it.

  4. Finally to make your client actually set up the remoting you have to kick start it when the application starts up. Open the global.asax and enter this line in the Application_Start event handler.
    Collapse
    protected void Application_Start(Object sender, EventArgs e)
    {
    RemotingConfiguration.Configure(Server.MapPath("Web.config"));//这里可以不注册web.config?
    }

    This will read the remoting section in the web.config and set it all in place (or generate a kick-ass remotingexception when you start up your webapp:)

Now go ahead and call the wrapper class LoginHandler from your web-client and enjoy the HttpCookie from the service:) Good luck!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Mads Nissen


http://weblogs.asp.net/mnissen
http://www.puzzlepart.com
Occupation: Software Developer (Senior)
Location: Norway Norway
如何实现高校科技成果转化的高效对接?.docx 科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。 立即下载

相关推荐

TinyML边缘智能振动诊断实战-ESP32完整工程-v1.0.zip

无硬件可完整体验:固件内置信号合成模拟器(严格复现训练物理模型),串口发 S0~S3 切换 4 种机器故障 算子级正确性:用 inspect_model_ops.py 从 tflite 解析出实际算子(EXPAND_DIMS/CONV_2D/RESHAPE/MEAN/FC/SOFTMAX),固件注册逐一对应——规避了 TFLite Micro 最常见的 "Op type not found" 坑 诚实标注:文档中明确区分“合成演示数据 / 工程近似 / 实测值”,并给出接入真实数据的完整流程

Remoting随想

二.Remoting基础 1.1 简介 Microsoft® .NET Remoting 提供了一种允许对象通过应用程序域与另一对象进行交互的框架。这种框架提供了多种服务,包括激活和生存期支持,以及负责与远程应用程序进行消息传输的通讯通道。简而言之,我们可以将其看作是一种分布式处理方式。这也正是我们使用Remoting的原因。 在Windows操作系统中,是将应用程序分离为单独的

发展是曲折的但也是前进的 1832

ffmpeg-Muti-solve-rtspnogood.zip

多路推流MP4本地切换测试。跨平台arm_win

HarmonyOS APP开发---“面对面“视频通话App,需要用到这个库

"面对面"要实现的是:用户 A 拨打视频电话给用户 B,B 接通后双方实时看到对方画面、听到对方声音,延迟在 200ms 以内。NAT 穿透:A 和 B 都在各自的家庭 WiFi 后面,怎么建立 P2P 连接?需要 ICE/STUN/TURN音频处理:扬声器声音别回灌到麦克风(AEC)、环境噪声要消除(ANS)、音量要自动调节(AGC)视频编解码:H.264/VP8/VP9 编解码 + 硬件加速带宽估计 + 拥塞控制:网络差时自动降码率,别卡成 PPTWebRTC。

OH_TPC的博客 213

基于SpringBoot+Vue校园失物招领系统的设计与实现

校园失物招领系统的设计与实现前端采用了Vue框架,并结合ElementUI来实现界面的设计与布局。后端采用了SpringBoot框架进行开发设计,并结合了Java语言和MySQL数据库来实现。在功能上分为了前端用户模块和管理员模块。前端用户模块主要实现了招领物品信息的发布、查询与管理,失物信息的发布、管理以及自动匹配招领物品,查看校园相关通知公告。管理员模块主要实现了物品分类管理、校园通知管理以及物品招领信息的查询统计等功能。校园失物招领系统的实现优化失物招领的流程,提高了校园失物招领的效率,促进了校园文化的建设,营造了良好的诚信氛围。

科技成果转化效率低怎么办?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

产业园区如何搭建统一的科技服务平台?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

复现基于改进秃鹰算法的微电网群经济优化调度研究(Matlab代码实现)

内容概要:本文围绕“基于改进秃鹰算法的微电网群经济优化调度”展开研究,提出了一种改进的秃鹰搜索算法(BES),旨在解决微电网群在复杂运行环境下的多目标、强约束、非线性及高维经济调度问题。通过引入特定优化策略,增强了基础算法的全局搜索能力和收敛效率,克服了传统智能算法易陷入局部最优的缺陷。研究构建了一个包含分布式电源、储能系统与多元负荷的微电网群调度模型,以最小化系统综合运行成本为核心目标,综合考虑功率平衡、设备出力能力、储能运行特性等多重约束条件。通过仿真实验验证了所提算法在调度精度、稳定性和计算效率方面相较于传统方法具有明显优势,并进一步展示了其在降低能源开支、提升可再生能源消纳水平方面的实际应用价值。; 适合人群:具备一定电力系统基础知识或优化算法背景,从事新能源调度、智能优化算法研究与应用等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于微电网群、综合能源系统等场景下的经济调度优化;②为秃鹰算法及其他群体智能算法的改进、复现与性能对比提供参考范例;③服务于科研仿真、算法验证及工程化应用需求。; 阅读建议:建议读者结合文中提供的Matlab代码实现进行实践操作,重点关注算法改进机制与调度模型的构建逻辑,同时可借助网盘资源获取完整资料,以加深对算法性能表现与应用场景的理解。

Obsidian 是一款本地优先的笔记与知识管理工具,基于 Markdown 文件存储,以双链(Bidirectional Links)为核心,帮助你构建个人知识网络

Obsidian 是一款本地优先的笔记与知识管理工具,基于 Markdown 文件存储,以双链(Bidirectional Links)为核心,帮助你构建个人知识网络

政府科技管理部门如何推动区域科技创新资源配置优化?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

高校如何快速搭建技术转化平台并提升科研成果推广效率?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

产业园区如何搭建科技服务平台?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

【多种改进粒子群算法进行比较】基于启发式算法的深度神经网络卸载策略研究边缘计算(Matlab代码实现)

内容概要:本文围绕“多种改进粒子群算法在深度神经网络卸载策略中的比较研究”展开,系统探讨了边缘计算环境下基于启发式优化算法的DNN任务卸载问题。文章首先剖析了传统粒子群算法(PSO)的基本原理及其在收敛性和全局搜索能力方面的局限性,继而深入介绍四种代表性改进算法:自适应权重PSO、混合遗传PSO、模拟退火PSO以及多目标PSO,详述其在提升寻优效率、增强鲁棒性及应对复杂多约束场景下的机制与优势。研究通过构建DNN卸载模型,设计多维度性能评估体系,在延迟、能耗、资源利用率等关键指标上对各类算法进行对比实验分析,进而提出面向不同应用场景的算法选型策略与优化建议。该工作为边缘智能系统中的计算任务调度提供了理论支撑与实践指导。; 适合人群:具备一定人工智能与优化算法基础,从事边缘计算、物联网、智能系统优化等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:① 掌握多种改进粒子群算法的核心思想与实现机制;② 理解深度神经网络在边缘-云协同环境下的任务卸载建模方法;③ 学习如何通过仿真实验对比不同启发式算法的性能差异,并根据实际需求选择最优算法方案; 阅读建议:建议结合提供的Matlab代码实现进行动手实践,重点关注算法参数调优、适应度函数设计及实验结果可视化分析过程,以深入理解算法行为与系统性能之间的内在关联。

上一篇: C#好文收藏
下一篇: [转] ASP.NET 设计中的 N 个技巧
doubleyou
博客等级 码龄22年 0粉丝 13原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值