2012-02-06 5 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에 대해 Binding/Endpoint 구성이 어떻게 생겼습니까? –

+0

초기 시도는 브라우저를 통해 이루어졌습니다. 엔드 포인트 구성을 추가했습니다. – Bullines

답변

2

IIS에서 "Require SSL"옵션을 설정하면 클라이언트 인증서를 사용하여 인증을 수행하고 있습니다. 클라이언트 인증서 인증이 없으면 해당 옵션을 무시하거나 비활성화하도록 설정하십시오.

HTTPS에서만 서비스를 제공하지 않으려면 웹 사이트의 "바인딩"옵션에서 HTTP 바인딩을 제거하십시오. 그렇지 않으면 전송을 보안 메커니즘으로 사용하도록 바인딩을 노출하고 HTTPS에서만 제공되는 WCF 서비스를 처리해야합니다.

UPDATE :

내가 https로 IIS에서 호스팅되는 RESTful 서비스가 방법에 찾아주세요 :

[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