2

I'm trying to use basic HTTP authentication with a REST service, but debugging proxy shows that no authentication headers are sent at all, they are ignored! Here is my code:

     WebChannelFactory<IMyService> factory = new WebChannelFactory<IMyService>(
        new WebHttpBinding(),
        new Uri("http://10.6.90.45:8081"));
     WebHttpBinding http = (WebHttpBinding) factory.Endpoint.Binding;
     http.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
     http.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly;

     factory.Credentials.UserName.UserName = "username";
     factory.Credentials.UserName.Password = "password";

IMyService proxy = factory.CreateChannel();

proxy.SomeMethod();

...

The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was ''.

Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest request, HttpWebResponse response, WebException responseException, HttpChannelFactory factory) at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) ...

Ivan G.
  • 5,027
  • 2
  • 37
  • 65

0 Answers0