2012-03-05 10 views
1

私はWCFレストWebサービスを作成しました。しかし、クライアントは基本認証でサービスをロックダウンするように要求しましたが、チャレンジではなく最初の応答で認証トークンを提示することができます。残念なことに私はテストマシンにIIS 6しか持っていません安心なWCFとFidderによる基本認証

私は基本認証をシミュレートする必要があります。したがって、匿名でこれを行い、認証トークンが間違っている場合はエラーを投げます。しかし、認証トークンは、WCFを使用できません

http://localhost/test.svc/get/token/

のContent-Type:アプリケーション/ x-www-form-urlencodedで

認証:基本Base64Value

私は匿名の削除や基本的な追加した場合IISで。私が得るのは401です.WCFの前にIISが認証をしていると思います。

理想的には、私はちょっとしたアクセスが好きで、認証ヘッダーにアクセスできるようにしたいと思っています。

どのように認証ヘッダを取得することができます

+0

あなたのWCF残りのWebサービスメソッドでHTTPヘッダを読み込むための方法をしたいですか? – CSharpenter

答えて

1

IIS 6の問題をbeeingて、このためのあなたの仮定はおそらく正しいです。

私はちょうどWCFサービス「xxx.svc」を作成し、IIS(7.5)でそれをホストされている、と私は正しいAuthorizationヘッダーでFiddler2をして、それを要求されたとき、それはHTTP 401

を送信しませんでした。 IIS 6でテストするようにコードを投稿します。HTTP 401が引き続き提供されている場合は、IIS 6の問題です。あなたのコードと私のコードを比較し、どのような構成が異なるかを確認してください。

web.configファイル:

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); 
     } 
    } 
} 
Service1.svc.cs:

<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

<%@ ServiceHost Language="C#" Debug="true" Service="MyTestSvc.MyService" CodeBehind="Service1.svc.cs" %> 

IService1.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 interface name "IService1" in both code and config file together. 
    [ServiceContract] 
    public interface IMyService 
    { 

     [OperationContract] 
     [WebGet([email protected]"/Hello")] 
     string GetData(); 

    } 
} 

、最終的にの

シオマネキ結果: Fiddler Composer request

fiddler inspector, request/response raw

+0

これは私がやっていることです。しかし、承認ヘッダーはありません – Chris

+0

あなたはWCF svcをホストしている仮想ディレクトリの認証モードとして**基本**を設定していますか? – CSharpenter

+0

はい私は基本設定をしましたが、基本設定には認証ヘッダが設定されていますが、base64文字列の場合は、IISがステップを踏んで401が発生します。 – Chris

関連する問題