R – The remote server returned an error: (401) Unauthorized in .NET Remoting

authenticationexception handlinghttp-status-code-401netremoting

I developed a remoting service (hosting .NET type in the ISS).
IIS is configured to use "Integrated Windows Auth".

It works perfectly when I execute unit test the service on the "localhost"
(the code below is the code I use for testing), but after I have deployed a service to the test server (which in another another domain),
it started throwing a "System.Net.WebException: The remote server returned an error: (401) Unauthorized." exception.

string url = string.Concat(@"http://", serverName, "/", ServiceName);

IDictionary props = new Hashtable();
props["useDefaultCredentials"] = true;
props["useAuthenticatedConnectionSharing"] = true;

BinaryServerFormatterSinkProvider srv = new BinaryServerFormatterSinkProvider();
BinaryClientFormatterSinkProvider clnt = new BinaryClientFormatterSinkProvider();
this.channel = new HttpChannel(props, clnt, srv);

ChannelServices.RegisterChannel(this.channel, false);

IMyService service = Activator.GetObject(typeof(IMyService), url) as IMyService;

service.GetData();// this error returns "System.Net.WebException: The remote server returned an error: (401) Unauthorized." exception.

What might be the issue? Is it domain related? May be it has something to do with a configuration of the default web proxy?

Best Answer

What credentials are you using? Is the system using Windows authentication? If so, does the other domain accept users from your domain?

You may have to define a trust relationship between domains, or log in with different and appropriate credentials for the server's domain.