2012-02-06 24 views
2

Windows Server 2008 R2サーバーでホストしたいRESTful WCFサービスがあります。現在、既存のウェブサイト内でアプリケーションとしてホストされています。自己署名証明書がポート443に使用されています。HTTPS経由のWCFサービス

サービスをHTTPS経由でのみ提供したいと思います。アプリケーションのSSL設定では、「SSLを要求する」に設定しました。次のようにエンドポイントの設定は次のとおりです。ただし

<system.serviceModel> 
<behaviors> 
    <endpointBehaviors> 
    <behavior name="Rest"> 
     <webHttp /> 
    </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 

    <behavior> 
     <serviceAuthorization serviceAuthorizationManagerType="ACME.MyAuthorizationManager, ACME.WS.Authorization" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
<standardEndpoints> 

    <webHttpEndpoint> 

    <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" /> 
    </webHttpEndpoint> 
</standardEndpoints> 

、ブラウザ(例えばhttps://example.com/myservices/baz-service/yip-resource)を介してサービスにアクセスしようとしたとき、私は403の応答を受信して​​います。

設定中に何か不足しましたか?

+0

どのようにサービスにアクセスしようとしていますか?ブラウザまたはwcfプロキシから? – BNL

+0

バインディング/エンドポイントの設定はあなたのsvcのようですか? –

+0

最初のアクセスはブラウザ経由で行われています。私はエンドポイントの設定を追加しました。 – Bullines

答えて

2

IISで[Require SSL]オプションを設定すると、クライアント証明書を使用して認証を実行していることを意味します。クライアント証明書認証がない場合は、そのオプションを無視または無効にするだけです。

サービスがHTTPSでのみ提供されるのを避けるには、Webサイトの[バインド]オプションからHTTPバインディングを削除します。そうでなければ、バインディングをセキュリティメカニズムとしてトランスポートを使用するように公開し、HTTPS上でのみサービスされるWCFサービスを処理する必要があります。

UPDATE:

私はRESTfulなサービスがhttpsでIISにホストされている必要がありどのように見つけてください:

[ServiceContract] 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 
    public class RestService 
    { 
     // TODO: Implement the collection resource that will contain the SampleItem instances 

     private static List<SampleItem> sampleCollection = new List<SampleItem>(); 

     [WebGet(UriTemplate = "/get-Collection")] 
     public List<SampleItem> GetCollection() 
     { 
      // TODO: Replace the current implementation to return a collection of SampleItem instances 
      if (sampleCollection.Count == 0) 
      { 
       sampleCollection = new List<SampleItem>(); 
       sampleCollection.Add(new SampleItem() { Id = 1, StringValue = "Hello 1" }); 
       sampleCollection.Add(new SampleItem() { Id = 2, StringValue = "Hello 2" }); 
       sampleCollection.Add(new SampleItem() { Id = 3, StringValue = "Hello 3" }); 
       sampleCollection.Add(new SampleItem() { Id = 4, StringValue = "Hello 4" }); 
       sampleCollection.Add(new SampleItem() { Id = 5, StringValue = "Hello 5" }); 
      } 
      return sampleCollection; 
     } 
} 

私のGlobal.asax:

public class Global : HttpApplication 
    { 
     void Application_Start(object sender, EventArgs e) 
     { 
      RegisterRoutes(); 
     } 

     private void RegisterRoutes() 
     { 
      // Edit the base address of Service1 by replacing the "Service1" string below 
      RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(RestService))); 
     } 
    } 

私のweb.configファイル:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 


    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </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> 
    <diagnostics> 
     <messageLogging logEntireMessage="true" logKnownPii="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" /> 
     <endToEndTracing propagateActivity="true" activityTracing="true" messageFlowTracing="true" /> 
    </diagnostics> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
    <standardEndpoints> 
     <webHttpEndpoint> 
     <!-- 
      Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
      via the attributes on the <standardEndpoint> element below 
     --> 
     <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxBufferSize="500000" maxReceivedMessageSize="500000">   
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />   
     </standardEndpoint> 
     </webHttpEndpoint> 
    </standardEndpoints> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name=""> 
       <serviceCredentials> 
        <serviceCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" findValue="localhost" /> 
       </serviceCredentials> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

今、私のIISは、HTTPSが指定されたバインディングました:

Site Bindings in IIS

今私の仮想ディレクトリは、名前XmlRestServiceで構成されているので、私は、リソースを参照するとき、私は以下の出力を得る:

Output from a REST Service on HTTPS

+0

現在、「クライアント証明書」が「無視」に設定されています。 – Bullines

+0

readerQuotasセクションは必要ありませんが、大量のデータを送信する必要がある場合は、それを残しておく方が良いでしょう。 – Rajesh

+0

そのstandardEndpointを使用すると、次のようになります。 バインディングWebHttpBindingを持つエンドポイントのスキームhttpに一致するベースアドレスを見つけることができませんでした。登録ベースアドレス方式は[https]です。 – Bullines

0

WCFを実装する方法はたくさんあります。多くの人のようにこの答えは私にとってはうまくいきませんでした。私は次の簡単な解決策を思いつきました。私はそれがおそらく最も普遍的な簡単な解決策だと思う。これは雄弁には見えないかもしれませんが、私たちの仕事の中ではそれほど評価されていない大部分の人にとっては、エラーを投げるのではなく、少なくともGET要求のためにリダイレクトを試みることができます。

#if !DEBUG 
    // check secure connection, raise error if not secure 
    IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest; 
    if (!request.UriTemplateMatch.BaseUri.AbsoluteUri.StartsWith("https://")) 
    { 
     throw new WebProtocolException(HttpStatusCode.BadRequest, "Https is required to use this service.", null); 
    } 
#endif 
関連する問題