我在WCF中遇到了一些身份验证问题,如果我从基于控制台的应用程序中使用该服务它运行正常但是如果我从asp.net尝试那么我得到:
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
我想我必须配置托管ASP页面的IIS,我尝试禁用匿名身份验证并启用Windows身份验证,但它不起作用。
我正在使用BasicHttpBinding,这是托管我的WCF的服务器上的web.config。
<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>
ASP.net和基于控制台的配置文件是相同的,所以我认为我应该在托管服务的IIS上工作。
如果我应该发布有关配置文件的代码或更多信息,请告诉我。
欢迎任何建议。
修改
这就是我在ASP页面上使用服务的方式,
Client client = new Client("BasicBinding");
try
{
string strResult = client.ProcessTransaction(strRequestDetails);
}
catch (FaultException ex)
{
lbMessage.Text = ex.Message;
}
在服务器站点上,这是抛出异常的行,请注意我在此单行中隔离了身份验证问题,
public string ProcessTransaction(string strRequestDetails)
{
return OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name;
使用asp.net 3.5和IIS 7.5