visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: General :: .NET REMOTING (IN C++)


By: omuyelijah Nigeria  Date: 30/05/2007 17:52:27  English  Points: 20 Status: Answered
Quality : Excellent
Hello,

I've posted this question in the Microsoft forums and yet waiting a reply but want to have it here. I have this problem exploring .NET remoting in Visual C++ 2005 Express Edition. This is a popular sample on the net but couldn't get it 2 work on my system. I tried this though using configuration files 4 the client and server and it worked well but doing it programmatically is proving heady. Just 2 add, I've made many more additions and subtractions 2 code w/o success.
I also in the process saw the startListening(System.Object) api on the Tcp and Http classes and even invoked them but still no success.

The output 4 both client and server is below while the codes are
furher down d page.

-------------- OUTPUT ----------------------

SERVER OUTPUT:
==============

Listening 4 requests @

PORT NAME: tcp
PORT: 8085
CHANNEL DATA: System.Runtime.Remoting.Channels.ChannelDataStore
CHANNEL PRIORITY: 1

CLIENT OUTPUT:
==============
Cannot create channel sink to connect to URL
'tcp:://localhost:8085/remotingType'. An appropriate
channel has probably not been registered.

------------------------------------------------


------------------ code ---------------------------------------------------

//remotable class
#include "stdafx.h"

namespace RemotingType {
using namespace System;

public ref class remotingType: public System::MarshalByRefObject
{
private: String^ Text;
public: property String^ remotingText{
String^ get(){ return Text;}
void set(String^ i){ Text="\n Welcome "+i;}
}

};
}


//CLIENT
// RemClient.cpp : main project file.

#include "stdafx.h"

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels::Tcp;

public ref class remClient{

public: remClient(){
try{

//create channel and register it. Well I don't know why this is necessary
TcpChannel^ ch=gcnew TcpChannel();
Channels::ChannelServices::RegisterChannel(ch,false);

RemotingType::remotingType^ remObj=
dynamic_cast<RemotingType::remotingType^>(
::Activator::GetObject( Type::GetType("RemotingType.remotingType, RemotingType"),
"tcp:://localhost:8085/remotingType")
);

if ( remObj != nullptr ){
remObj->remotingText="omuyelijah@gmail.com";
Console::WriteLine(remObj->remotingText);
}
else Console::WriteLine(" Could not get access to object... ");


}
catch(Exception^ e){ Console::WriteLine(e->Message);}

}

};

int main(array<System::String ^> ^args)
{
remClient^ ss=gcnew remClient();
return 0;
}

//SERVER
// RemServer.cpp : main project file.

#include "stdafx.h"

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels::Tcp;

public ref class remServer{

public: remServer(){
try{

//create an TCP channel
TcpChannel^ chan=gcnew TcpChannel(8085);


//register channel and start listening
Channels::ChannelServices::RegisterChannel(chan,false);



//register service i.e. remotable class
RemotingConfiguration::RegisterWellKnownServiceType(
Type::GetType("RemotingType.remotingType, RemotingType"),
"remotingType",WellKnownObjectMode::Singleton);

Console::WriteLine(" Listening 4 requests @ \n");
Console::WriteLine(" PORT NAME: " + chan->ChannelName + "\n PORT: " + 8085 );
Console::WriteLine(" CHANNEL DATA: " + chan->ChannelData->ToString() );
Console::WriteLine(" CHANNEL PRIORITY: " + chan->ChannelPriority.ToString() + "\n");

//well start listening
chan->StartListening(nullptr);

Console::ReadLine();

//stop listening ...
chan->StopListening("remotingType");

}
catch(Exception^ e){ Console::WriteLine(e->Message);}

}

};

int main(array<System::String ^> ^args)
{
remServer^ a=gcnew remServer();
return 0;
}

-------------------------------------------------------------------------
By: omuyelijah Date: 01/06/2007 20:17:42 English  Type : Comment
Hello,

It appears this is one question appearing in almost all forums unanswered. I finally found a solution for the problem and want to share it with all. First , about my system.
OS NAME: Windows XP SP2 Home Edition
.NET framework Version: 2.0
Compiler: MS Visual C++ 2005 Express Edition SP1 (Just updated to it) yesterday.

EXCEPTION: Unable to create channel sink to connect to url <&#8230;>
an appropriate channel has probably not been configured.


I got this error when I was just exploring it too as a beginner and in the course of searching through the internet saw this same error in quite a lot of forums w/o a credible answer. I wrote the remoting class (as an interface and compiled it to a .dll file to be referenced by client and server).
On running the server, and then client, the error pops up on client window.

There are 2 possible causes:

a) When you type the objectUrl in the remoting client code as say &#8220;http://localhost:8080/remClass.rem&#8221;, as in

Activator::getObject( Type::getType(&#8220;RemotableClass&#8221;,&#8221; &#8220;http://localhost:8080/remClass.rem&#8221;))

did you get it automatically underlined? If not, ur compiler cannot/did detect the url and so this is the cause of the error. This was what I experienced, until I had completely updated my system (Windows update offered me Visual C++ 2005 Express Edition SP1) before the error vanished. Consider updating ur system too (if not updated) and I think it will work 4 u, or u might try
retyping the url until it is detected. There might be some settings to help out with this too. Here is a sample image below 4 ur viewing.



b) Windows Firewall: Your firewall might block all network access. Check the windows firewall in Control Panel 4 ur remote application.
1.If you find your remoting program (in the list) unticked, Windows will block network access to or from it so Tick it so that ur programs will work (or just remove it from the list and re-run ur application,
so Windows can re-enlist it again).
2.If you can&#8217;t find ur remoting application in the list (after a lot of ur running the application especially if the application is the remoting server), it means there is either no channel created (with a port) or not created
well. Windows will always see every program opening a channel for remoting and display a notification to let u unblock or allow the application.

Just to add, ensure that you don&#8217;t type ur url in this format
http:port//localhost/objecturi.rem. or
@http:port//localhost/objecturi.rem. or
@http:://localhost:port/objecturi.rem

Follow the format used above i.e.
http:://localhost:port/objecturi.rem
By: omuyelijah Date: 01/06/2007 20:21:09 English  Type : Answer
Hello,

It appears this is one question appearing in almost all forums unanswered. I finally found a solution for the problem and want to share it with all. First , about my system.
OS NAME: Windows XP SP2 Home Edition
.NET framework Version: 2.0
Compiler: MS Visual C++ 2005 Express Edition SP1 (Just updated to it) yesterday.

EXCEPTION: Unable to create channel sink to connect to url <...>
an appropriate channel has probably not been configured.

I got this error when I was just exploring it too as a beginner and in the course of searching through the internet saw this same error in quite a lot of forums w/o a credible answer. I wrote the remoting class (as an interface and compiled it to a .dll file to be referenced by client and server).
On running the server, and then client, the error pops up on client window.

There are 2 possible causes:

a) When you type the objectUrl in the remoting client code as say http://localhost:8080/remClass.rem as in

Activator::getObject( Type::getType(RemotableClass,http://localhost:8080/remClass.rem))

did you get it automatically underlined? If not, ur compiler cannot/did detect the url and so this is the cause of the error. This was what I experienced, until I had completely updated my system (Windows update offered me Visual C++ 2005 Express Edition SP1) before the error vanished. Consider updating ur system too (if not updated) and I think it will work 4 u, or u might try
retyping the url until it is detected. There might be some settings to help out with this too. Here is a sample image below 4 ur viewing.




b) Windows Firewall: Your firewall might block all network access. Check the windows firewall in Control Panel 4 ur remote application.
1.If you find your remoting program (in the list) unticked, Windows will block network access to or from it so Tick it so that ur programs will work (or just remove it from the list and re-run ur application,
so Windows can re-enlist it again).
2.If you cant find ur remoting application in the list (after a lot of ur running the application especially if the application is the remoting server), it means there is either no channel created (with a port) or not created
well. Windows will always see every program opening a channel for remoting and display a notification to let u unblock or allow the application.

Just to add, ensure that you dont type ur url in this format
http:port//localhost/objecturi.rem. or
@http:port//localhost/objecturi.rem. or
@http:://localhost:port/objecturi.rem

Follow the format used above i.e.
http:://localhost:port/objecturi.rem
By: omuyelijah Date: 02/06/2007 19:08:53 English  Type : Comment
Hello,

Sorry, I am still making the mistake above that is causing the error, instead of correcting it. The mistake is from the fact that the objectUri is typed incorrectly. To overcome the error, please use the format below:

http://localhost:port/objectUri.rem

or

tcp://localhost:port/objectUri.rem

I see that the error is typographic. Most people get it becos they write

http:://localhost:port/objectUri

or

tcp:://localhost:port/objectUri

These 2 are wrong becos of the double colon after the channel. Therefore,
DO NOT USE A DOUBLE COLON THERE

Lastly, let me also add that url detection as I pointed out above only works if the url begins with http and is not particularly common with tcp.



PLEASE BEAR WITH ME.

Do register to be able to answer

EContact
browser fav
page generated in 359.655140 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page