相关疑难解决方法(0)

将基本HTTP身份验证添加到WCF REST服务

我有一个WCF HTTP REST服务,我使用不同编程语言的HTTP客户端编写自己的自定义HTTP.我想为我的WCF服务添加WWW-Authenticate基本身份验证支持.

我的方法看起来像这样:

[WebInvoke(UriTemplate = "widgets", Method = "POST")]
public XElement CreateWidget(XElement e)   
{
...
}
Run Code Online (Sandbox Code Playgroud)

是否有可能以某种方式过滤传入的HTTP请求,以便我可以检查有效的Basic auth字符串,然后才能访问上面的每个REST方法CreateWidget?注意:我的身份验证信息在我的数据库中是stord.

基本上我想在请求头中检查这个: Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==然后我可以自己解析该字符串并验证数据库中的u/p.

web.config文件如下:

<?xml version="1.0"?>
<configuration>

  <connectionStrings>
    <add name="DatabaseConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Database;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="10485760" />
  </system.web>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
  </system.webServer>

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="1048576" maxBufferSize="1048576" />
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>

</configuration>
Run Code Online (Sandbox Code Playgroud)

authentication wcf http

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

authentication ×1

http ×1

wcf ×1