Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to include remoting configuration

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

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

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

604 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