Solved

How to include remoting configuration

Posted on 2004-08-23
1
384 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
The viewer will learn how to dynamically set the form action using jQuery.
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.

690 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