Note that there are some explanatory texts on larger screens.

plurals
  1. POConsuming REST Service with WCF - Basic Authentication
    primarykey
    data
    text
    <p>I'm trying to consume a REST service with Basic Authentication with an odd problem. The first request made does not include the basic authentication credentials specified. This happens for every first request made. It happens every time the application starts. It does not happen for subsequent requests. I am using the <code>ClientBase&lt;T&gt;</code> class to call the API, which looks something like this:</p> <pre><code>public class MyApi : ClientBase&lt;IMyApi&gt; { protected override IMyApi CreateChannel() { //Remove all client credentials. ChannelFactory.Endpoint.Behaviors.RemoveAll&lt;ClientCredentials&gt;(); //Create new client credentials and add to the endpoint behaviours. ClientCredentials clientCredentials = new ClientCredentials(); clientCredentials.UserName.UserName = Username; clientCredentials.UserName.Password = Password; ChannelFactory.Endpoint.Behaviors.Add(clientCredentials); return base.CreateChannel(); } public MyApi() : base (DefaultEndpointName) {} } </code></pre> <p>My binding is setup as follows:</p> <pre><code> &lt;customBinding&gt; &lt;binding name="myApiBinding"&gt; &lt;webMessageEncoding webContentTypeMapperType="ContentTypeMapper,Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /&gt; &lt;httpTransport manualAddressing="true" maxReceivedMessageSize="6553600" authenticationScheme="Basic" realm="myRealm" /&gt; &lt;/binding&gt; &lt;/customBinding&gt; </code></pre> <p>I have tried bumping the project up to .Net 4, adding the client credentials after initialising the API, but none seem to have the desired the effect.</p> <p>Is there a way to get the credentials added for every request?</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.
    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