Note that there are some explanatory texts on larger screens.

plurals
  1. PONot passing Credentials to WCF Service resulting in a 401
    primarykey
    data
    text
    <p>I'm tearing my hair out on this one, I have a WCF service that I can call through the browser and it works fine, when I call it from the web application with the below method I get a <strong>(401) Unauthorized</strong> error. And the service does not get called. What's more, when I run my web application from my local machine (debug mode using IIS Express) pointed at my dev server (IIS7) it works but when I deploy my web application to the dev server and point it to the dev server services it fails wit the 401 error. I think this is something to do with IIS7 but I'm not 100% sure and help would be super useful.</p> <p>I have looked online for the answers but thus far the best I have found is <a href="http://jgvimalan.wordpress.com/2010/10/14/using-windows-identity-and-impersonation-with-wcf-on-iis-7/">this</a>.</p> <p>My service call is as follows:</p> <pre><code>var request = (HttpWebRequest) WebRequest.Create(url); request.Method = "GET"; request.ContentType = "application/json; charset=utf-8"; request.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested; request.Credentials = CredentialCache.DefaultCredentials; WebResponse responce = request.GetResponse(); Stream reader = responce.GetResponseStream(); var sReader = new StreamReader(reader); string outResult = sReader.ReadToEnd(); sReader.Close(); var result = (T) JsonConvert.DeserializeObject(outResult, typeof (T)); return result; </code></pre> <p>My configuration for the service looks like this :</p> <pre><code> &lt;service name="RGMPServices.Householding.Services.AccountService" behaviorConfiguration="Default"&gt; &lt;endpoint address="" kind="webHttpEndpoint" endpointConfiguration="SecuredHttpEndpointBinding" contract="RGMPServices.Householding.Contracts.IAccountService" /&gt; &lt;/service&gt; &lt;service name="RGMPServices.Householding.Services.HouseholdService" behaviorConfiguration="Default"&gt; &lt;endpoint address="" kind="webHttpEndpoint" endpointConfiguration="SecuredHttpEndpointBinding" contract="RGMPServices.Householding.Contracts.IHouseholdService" /&gt; &lt;/service&gt; &lt;service name="RGMPServices.Householding.Services.UserService" behaviorConfiguration="Default"&gt; &lt;endpoint address="" kind="webHttpEndpoint" endpointConfiguration="SecuredHttpEndpointBinding" contract="RGMPServices.Householding.Contracts.IUserService" /&gt; &lt;/service&gt; &lt;/services&gt; &lt;behaviors&gt; &lt;endpointBehaviors&gt; &lt;behavior name="webBehaviour"&gt; &lt;webHttp /&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="Default"&gt; &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /&gt; &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; &lt;standardEndpoints&gt; &lt;webHttpEndpoint&gt; &lt;standardEndpoint name="SecuredHttpEndpointBinding" helpEnabled="true" automaticFormatSelectionEnabled="true"&gt; &lt;security mode="TransportCredentialOnly"&gt; &lt;transport clientCredentialType="Windows" /&gt; &lt;/security&gt; &lt;/standardEndpoint&gt; &lt;/webHttpEndpoint&gt; &lt;/standardEndpoints&gt; </code></pre> <hr> <p>I have put some logging on the client service call, just before I call the service, the response is:</p> <blockquote> <p>DEBUG 2013-10-01 13:15:13,569 452ms ServiceGetSingle - Passing Login: MYLANDOMAIN\MYLANUSERNAME</p> <p>ERROR 2013-10-01 13:15:13,631 514ms ServiceGetSingle - ERROR Calling ServiceGetSingle with user credentials login: MYLANDOMAIN\MYLANUSERNAME System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() at Householding.Common.ServiceHelper.ServiceGetSingle[T](String url)</p> </blockquote> <p>The code looks like:</p> <pre><code>logger.Debug("Passing Login: " + System.Security.Principal.WindowsIdentity.GetCurrent().Name) </code></pre> <hr> <p>Even when I set the AppPool for my website to my domain account it is still not authorising me to access the WCF Service, but again: it's working for the browser. So weird!</p>
    singulars
    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