locked
How to setup programmatically channels?

    Question

  • Hi,
    I want to configure a http server channel and a http client channel programmatically instead using configuration files. I'd like to know the correct syntax to translate the following configurations files

    Client

    <configuration>
      <system.runtime.remoting>
        <application>

          <channels>
             <channel ref="http" secure="true"  port="0" />
          </channels>

          <client>
            <wellknown type="General.IBroadcaster, General" 
            url="http://localhost:5555/Broadcaster" />
          </client>

        </application>
      </system.runtime.remoting>
    </configuration>

    Server

    <configuration>
      <system.runtime.remoting>
        <application>
          <channels>
            <channel ref="http" secure="true"  port="5555">
              <serverProviders>           
                            <provider ref="wsdl" />
                <formatter ref="soap" typeFilterLevel="Full" />
                <formatter ref="binary" typeFilterLevel="Full" />
              </serverProviders>
            </channel>
          </channels>
          <service>
            <wellknown mode="Singleton" type="Broadcaster, Server" objectUri="Broadcaster" />
          </service>
        </application>
      </system.runtime.remoting>
    </configuration>

    Thanks
    Marco
    Friday, October 06, 2006 7:35 AM

All replies

  • Use the System.Runtime.Remoting.RemotingConfiguration class.
    Monday, October 09, 2006 1:04 AM
    Moderator
  • Of course I allready use the code:
        RemotingConfiguration::Configure(filename, false);
    to make things works.
    I meant the equivalent code... some like the following:

        SoapServerFormatterSinkProvider ^serverProv = gcnew SoapServerFormatterSinkProvider();
        serverProv->TypeFilterLevel = System::Runtime::Serialization::Formatters::TypeFilterLevel::Full;
        IDictionary ^props = gcnew Hashtable();
        props["port"] = 5555;
        props["name"] = "Server";

        HttpServerChannel ^channel = gcnew HttpServerChannel(props, serverProv);

        ChannelServices::RegisterChannel(channel, false);


    I tried to use the above code but it doesn't give the same result as config file
    Marco
    Monday, October 09, 2006 6:48 AM
  • Looks like you are missing the call to register the well-known object as the service type (the "wellknown" element from your configuration file). Something like this (in C#; you'll have to translate to C++):



    System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(Broadcaster), "Broadcaster", WellKnownObjectMode.Singleton);

     

    Monday, October 09, 2006 4:24 PM
    Moderator
  • I didn't miss it in my code I just missed it in the post. So here my whole code for server and client.

    Server
        SoapServerFormatterSinkProvider ^serverProv = gcnew SoapServerFormatterSinkProvider();
        serverProv->TypeFilterLevel = System::Runtime::Serialization::Formatters::TypeFilterLevel::Full;
        IDictionary ^props = gcnew Hashtable();
        props["port"] = 5555;
        props["name"] = "Server";

        HttpServerChannel ^channel = gcnew HttpServerChannel(props, serverProv);

        ChannelServices::RegisterChannel(channel, false);
       
        WellKnownServiceTypeEntry ^remObj = gcnew WellKnownServiceTypeEntry
        (
            Broadcaster::typeid,
            "Broadcaster",
            WellKnownObjectMode::Singleton
        );

        RemotingConfiguration::RegisterWellKnownServiceType(remObj);
        Console::WriteLine ("Server started, press <return> to exit.");

        IBroadcaster ^bcast = (IBroadcaster^)Activator::GetObject(IBroadcaster::typeid, "http://localhost:5555/Broadcaster");

    Client

        System::Collections::Hashtable^ properties = gcnew System::Collections::Hashtable;
        properties["port"] = 0;
        properties["secure"] = true;
        IClientChannelSinkProvider^ sinkProvider = nullptr;
        HttpClientChannel^ channel = gcnew HttpClientChannel( properties,sinkProvider );
        ChannelServices::RegisterChannel(channel, false);
        IBroadcaster ^bcaster = (IBroadcaster^)Activator::GetObject(IBroadcaster::typeid, "http://localhost:5555/Broadcaster");

    I can get the remote object. Then I register the event handler, impleneted as a delegate, but when the server try to call the event handler I get the following error:

    An unhandled exception of type 'System.Runtime.Remoting.RemotingException' occurred in mscorlib.dll

    Additional information: This remoting proxy has no channel sink which means either the server has no registered server channels that are listening, or this application has no suitable client channel to talk to the server.

    If I use the config file instead of code everything works well. I don't understand what is wrong!
    Marco
    Tuesday, October 10, 2006 7:19 AM