Solved

How to include remoting configuration

Posted on 2004-08-23
1
381 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error on link 14 46
C# bracket error 3 30
Add different cell to otherwise similiar row 4 37
FTP file download using c# 3 21
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…
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 …
The viewer will learn how to count occurrences of each item in an array.
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)

813 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