Note that there are some explanatory texts on larger screens.

plurals
  1. PODouble request while making POX REST call using WCF with WebHttpBinding set to Basic Authentication
    primarykey
    data
    text
    <p>Having an issue while making POX REST call using WCF with WebHttpBinding set to Basic Authentication (HttpClientCredentialType.Basic)</p> <p>Instead of one call from the client with “Authorization: Basic” specified in HTTP Header, two calls are made. First call without authentication at all to which service responses with 401 Unauthorized error, second call with proper authentication info.</p> <p>This seems to be handled by WCF service with no hiccup at all. Calling third party services obviously creates a problem since they respond with error immediately.</p> <p>Service Code:</p> <pre><code>[ServiceContract] public interface IService { [OperationContract] [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, UriTemplate = "")] Message SendData(Message message); } public class Service : IService { public Message SendData(Message message) { return Message.CreateMessage(MessageVersion.None, String.Empty, "test"); } } </code></pre> <p>Client Code: </p> <pre><code>public class Client: WebChannelFactory&lt;IService&gt;, IService { public Client(Uri baseUri, string userName, string password) : base(CreateBinding(), baseUri) { Credentials.UserName.UserName = userName; Credentials.UserName.Password = password; } public Message SendData(Message requestMessage) { var channel = CreateChannel(); Message responseMessage = channel.SendData(requestMessage); return responseMessage; } private static Binding CreateBinding() { var binding = new WebHttpBinding(); binding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; return binding; } } </code></pre> <p>Using TcpTrace I’m seeing these to requests back to back: </p> <pre><code>POST / HTTP/1.1 Content-Type: application/xml; charset=utf-8 VsDebuggerCausalityData: uIDPo2lH6p+lUOdFmrqDKGWYeQkAAAAA7+Y4QR6wNUWZmwCaasMx7xrfcJZxph9NocstwCh8NQsACQAA Host: localhost:9090 Content-Length: 89 Expect: 100-continue Connection: Keep-Alive &lt;string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"&gt;test request&lt;/string&gt; POST / HTTP/1.1 Content-Type: application/xml; charset=utf-8 VsDebuggerCausalityData: uIDPo2lH6p+lUOdFmrqDKGWYeQkAAAAA7+Y4QR6wNUWZmwCaasMx7xrfcJZxph9NocstwCh8NQsACQAA Authorization: Basic dGVzdDp0ZXN0 Host: localhost:9090 Content-Length: 89 Expect: 100-continue &lt;string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"&gt;test request&lt;/string&gt; </code></pre> <p>Note only second call contains: <strong>Authorization: Basic dGVzdDp0ZXN0</strong> How to stop the first request (without authorization) to be made?</p> <p>Sample solution with TcpTrace utility can be downloaded here:</p> <p><a href="http://www.coohya.com/WCF-BasicAuthenticationIssue.zip" rel="nofollow noreferrer">WCF-BasicAuthenticationIssue.zip</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload