Restful WCF和通过FIDER的基本身份验证
我已经创建了一个WCF rest web服务。但是,客户端已请求使用基本身份验证锁定服务,但允许他们在第一次响应时提供授权令牌,而不是质询。不幸的是,我的测试机上只有IIS 6 我只需要模拟基本的身份验证,这样我就可以通过匿名进行验证,如果授权令牌不正确,就会抛出一个错误。但是,身份验证令牌对WCF不可用 内容类型:application/x-www-form-urlencoded 授权:基本Base64Value 如果我删除匿名并在IIS中添加basic。我得到的只是401。我猜是IIS在WCF之前进行身份验证 理想情况下,我只希望能够进行匿名访问,并能够访问授权标头Restful WCF和通过FIDER的基本身份验证,wcf,authentication,rest,fiddler,basic-authentication,Wcf,Authentication,Rest,Fiddler,Basic Authentication,我已经创建了一个WCF rest web服务。但是,客户端已请求使用基本身份验证锁定服务,但允许他们在第一次响应时提供授权令牌,而不是质询。不幸的是,我的测试机上只有IIS 6 我只需要模拟基本的身份验证,这样我就可以通过匿名进行验证,如果授权令牌不正确,就会抛出一个错误。但是,身份验证令牌对WCF不可用 内容类型:application/x-www-form-urlencoded 授权:基本Base64Value 如果我删除匿名并在IIS中添加basic。我得到的只是401。我猜是IIS在W
如何获取身份验证标题您对这一问题的假设是IIS6可能是正确的 我刚刚创建了一个WCF服务“xxx.svc”,并将其托管在IIS(7.5)中,当我使用具有正确授权头的fiddler2请求它时,它没有发送HTTP 401 我将发布我的代码,以便您在IIS 6上测试它。如果它仍然提供HTTP401,那么这肯定是IIS6的问题,如果不是的话,请尝试将您的代码与我的代码进行比较,看看哪些配置不同 web.config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindConfig">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="MyTestSvc.MyService">
<endpoint address="http://localhost/TestBasicAuth/Service1.svc" behaviorConfiguration="webHttpEndpointBehavior"
binding="webHttpBinding" bindingConfiguration="webHttpBindConfig"
name="webHttpBindingEndpoint" contract="MyTestSvc.IMyService" />
<host>
<baseAddresses>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webHttpEndpointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
最后:Service1.svc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace MyTestSvc
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class MyService : IMyService
{
public string GetData()
{
WebOperationContext webCtx = WebOperationContext.Current;
IncomingWebRequestContext incomingCtx = webCtx.IncomingRequest;
string hdrVal = incomingCtx.Headers["Authorization"];
return string.Format("Authorization: {0}", hdrVal);
}
}
}
fiddler结果:
您对IIS 6问题的假设可能是正确的 我刚刚创建了一个WCF服务“xxx.svc”,并将其托管在IIS(7.5)中,当我使用具有正确授权头的fiddler2请求它时,它没有发送HTTP 401 我将发布我的代码,以便您在IIS 6上测试它。如果它仍然提供HTTP401,那么这肯定是IIS6的问题,如果不是的话,请尝试将您的代码与我的代码进行比较,看看哪些配置不同 web.config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindConfig">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="MyTestSvc.MyService">
<endpoint address="http://localhost/TestBasicAuth/Service1.svc" behaviorConfiguration="webHttpEndpointBehavior"
binding="webHttpBinding" bindingConfiguration="webHttpBindConfig"
name="webHttpBindingEndpoint" contract="MyTestSvc.IMyService" />
<host>
<baseAddresses>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webHttpEndpointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
最后:Service1.svc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace MyTestSvc
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class MyService : IMyService
{
public string GetData()
{
WebOperationContext webCtx = WebOperationContext.Current;
IncomingWebRequestContext incomingCtx = webCtx.IncomingRequest;
string hdrVal = incomingCtx.Headers["Authorization"];
return string.Format("Authorization: {0}", hdrVal);
}
}
}
fiddler结果:
您想在WCF Rest web服务方法中读取HTTP头吗?您想在WCF Rest web服务方法中读取HTTP头吗?这就是我正在做的。但是授权标头不在那里,并且您已将basic设置为承载WCF svc的虚拟目录的身份验证模式?是的,我现在已设置basic,但当设置basic时,身份验证标头在那里,但当它是base64字符串时,在代码命中之前,IIS步骤将导致401。这必须在IIS上工作。我们还需要做其他与IIS相关的事情。可能是IIS6。这就是我在做的。但是授权标头不在那里,并且您已将basic设置为承载WCF svc的虚拟目录的身份验证模式?是的,我现在已设置basic,但当设置basic时,身份验证标头在那里,但当它是base64字符串时,在代码命中之前,IIS步骤将导致401。这必须在IIS上工作。我们还需要做其他与IIS相关的事情。可能是IIS6。