走进.Net Remoting(二)×配置

在上节中,我们创建了一个简单的分布式应用,这一节我们将介绍如何通过配置文件实现上节中的服务端和客户端,由于对配置文件的修改,不需要修改代码,重新编译程序,所以我们建议在以后的应用中,尽可能的使用配置文件来定义通道、端口、对象等等。

 

上节中服务端应用,在项目中添加配置文件RemotingServerSao.config

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <system.runtime.remoting>

    <application>

      <service>

        <wellknown

       mode="SingleCall"    type="Enterprise.Northwind.Business.Remoting.RemotingCustomersBO,

Enterprise.Northwind.Business.Remoting"

           objectUri="CustomersBO.soap"

            />

      </service>

      <channels>

        <channel ref="http" port="1234"/>

      </channels>

    </application>

  </system.runtime.remoting>

</configuration>

 

服务端代码修改为:

 

    class Program

    {

        static void Main(string[] args)

        {

              RemotingConfiguration.Configure("RemotingServerSao.config",false);

              Console.WriteLine("Server starts as Sao. Press Enter to exit...");

              Console.ReadLine();

        }

 

客户端应用中,添加配置文件RemotingClientSao.config

 

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <system.runtime.remoting>

    <application>

      <client>

        <wellknown

           type="Enterprise.Northwind.Business.Remoting.RemotingCustomersBO, Enterprise.Northwind.Business.Remoting"

           url="http://localhost:1234/CustomersBO.soap"

            />

      </client>

      <channels>

        <channel ref="http">

        </channel>

      </channels>

    </application>

  </system.runtime.remoting>

</configuration>

 

客户端代码修改为:

 

    class Program

    {

        static void Main(string[] args)

        {

            RemotingConfiguration.Configure("RemotingClientSao.config", false);    

       ICustomersBO customersBO = new RemotingCustomersBO();

            Console.WriteLine(customersBO.GetCustomerNameByID(3));

            Console.ReadLine();

                       

        }

}

 

 

关于对象生命期、ClientProvidersServerProviders的配置我们会在后面的章节中使用到的时候再介绍。

 

注:本系列文章乃作者原创,转载请注明出处,谢谢。

 

转载于:https://www.cnblogs.com/ksxs/archive/2007/06/22/793214.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值