1

I'm facing some problems with authentication in my WCF, if I consume the service from a console-based app it works fine but if I try from asp.net then I get:

The remote server returned an error: (401) Unauthorized.

[WebException: The remote server returned an error: (401) Unauthorized.]
System.Net.HttpWebRequest.GetResponse() +1126
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +81

[MessageSecurityException: The HTTP request is unauthorized with client authentication    scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +10259322

I guess I have to configure the IIS where ASP page is hosted, I tried disabling anonymous authentication and enabling Windows Authentication but it does not work.

I'm using BasicHttpBinding and this is my web.config on the server where my WCF is hosted.

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="basicBinding">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </basicHttpBinding>   
</bindings>
<services>
  <service name="Service1" behaviorConfiguration="ServiceBehavior" >
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicBinding" contract="Contract1"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="True"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

The ASP.net and console-based config files are the same so I think I should work on the IIS where the service is hosted.

Please let me know if I should post the code or more information about the config files.

Any advice is welcome.

EDIT

This is how I consuming the service on the ASP page,

    Client client = new Client("BasicBinding");
    try
    {
        string strResult = client.ProcessTransaction(strRequestDetails);
    }
    catch (FaultException ex)
    {
        lbMessage.Text = ex.Message;
    }

On the server site, this is the line where the exception is being thrown, notice I isolated the authentication issue in this single line,

    public string ProcessTransaction(string strRequestDetails)
    {
        return OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name;

Using asp.net 3.5 and IIS 7.5

4

0 回答 0