Solved

How to include remoting configuration

Posted on 2004-08-23
1
380 Views
Last Modified: 2013-11-18
Ola,

I have this client in C# that makes use of remoting. The remtoing gets configerd by an external xml file to make ti more dynamic after the program has been compiled.
But now I dont need the program to be dynamic and I want to have everything included in this 1 client.cs file so that I can easily use this code from ASP.NET aswell.

here is the client.cs:

// console app
using System;
using System.Configuration;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Activation;

class Client
{
      static void Main()
      {
            RemotingConfiguration.Configure("client.exe.config");

            ICalc c = (ICalc)
                  RemotingServices.Connect(typeof(ICalc), ConfigurationSettings.AppSettings["calcURL"]);

            Console.WriteLine("c.AppDomainName (Calc) = {0}", c.AppDomainName);
            Console.ReadLine();
      }
}

and this is the application configuartion file ( app.config ):

<!-- xml -->
<configuration>
  <appSettings>
    <add key="calcURL" value="http://localhost:999/calcsrv/calc"/>
  </appSettings>

  <system.runtime.remoting>
    <application name="client">
      <channels>
        <channel ref="http" port="0">
          <clientProviders>
            <formatter ref="binary" />
          </clientProviders>
          <serverProviders>
            <formatter ref="binary" />
          </serverProviders>
        </channel>
      </channels>
    </application>
  </system.runtime.remoting>
</configuration>
0
Comment
Question by:DaFou
1 Comment
 
LVL 10

Accepted Solution

by:
eternal_21 earned 500 total points
ID: 11874271
This should do it:

### C#.NET ###

using System;

class Client
{
  static void Main()
  {
    System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider serverProv;
    serverProv = new System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider();
    serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

    System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider clientProv;
    clientProv = new System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider();

    System.Collections.IDictionary props = new System.Collections.Hashtable();
    props["port"] = 0;

    System.Runtime.Remoting.Channels.IChannel channel;
    channel = new System.Runtime.Remoting.Channels.Http.HttpChannel(props, clientProv, serverProv);
    System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel);

    ICalc c = (ICalc)System.Runtime.Remoting.RemotingServices.Connect(typeof(ICalc), "http://localhost:999/calcsrv/calc");
           
    Console.WriteLine("c.AppDomainName (Calc) = {0}", c.AppDomainName);
    Console.ReadLine();
  }
}

###
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now