?
Solved

How to include remoting configuration

Posted on 2004-08-23
1
Medium Priority
?
385 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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.
Suggested Courses

764 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