Wednesday, February 13, 2008

.NET Remoting in non-domain enviroments

Wow, talk about a hair puller ... I hope this helps someone working on a .NET application where they need to communicate in a domain-less or workgroup situation. Basically my application is run on almost strictly Windows XP machines, but the user can choose to make their application the "server", thus starting a TCPServerChannel.



Server Code --------------

if(makeMeAServer) 
{
RemotingConfiguration.Configure("config file", true);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(SomeRemoteableObject), "SomeMethod", WellKnownObjectMode.SingleCall);
}


Server Config File ------------

<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" secure="true" protectionlevel="EncryptAndSign" port="8080">
<serverproviders>
<formatter ref="binary">
</formatter>
</serverproviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
Thanks to .NET 2.0, the TCP channel can be secured, but the gotcha I ran into was that I couldn't authenticate the client (call it "WinXP Client") using a TCPClientChannel with the newly created server (call it "WinXP Server") in a workgroup enviroment.

Obviously this was because of a credentials issue. "No problem" I thought, I'll just add a new user who is valid on "WinXP Server" to "WinXP Client" with the same name and password. Pretty standard stuff to get NTLM to kick in. Guess what, it still didn't work!

WTF mate?



To make a long story short, after spending quite a bit of time on various seach engines and forums, it all boiled down to the fact that Windows XP has "Use simple file sharing (Recommended)" enabled by default for workgroup computers (maybe domained ones as well?). After I unchecked this option (Tools -> Folder Options -> View), it worked like a champ. I need to go back and see if passing username, password and domain(i.e. machine name) as parameters to the TCPClientChannel will work, but that's not necessary at the moment for me.

BTW, here is the client side config file and necessary code ...



Client Config File -----------------

<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" secure="true" impersonationlevel="Impersonation" protectionlevel="EncryptAndSign">
<clientproviders>
<formatter ref="binary" typefilterlevel="Full">
</formatter>
<serverproviders>
<formatter ref="binary" typefilterlevel="Full">
</formatter>
</serverproviders>
</clientproviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
Client Code -----------

RemotingConfiguration.Configure("Client.exe.config", true);
SomeRemoteableObject test = (SomeRemoteableObject )Activator.GetObject(typeof(SomeRemoteableObject), "tcp://remoteserver:8080/SomeMethod");
Console.WriteLine(test.LastNameOrWhateverProperty);

No comments:

Post a Comment