简体   繁体   English

WCF REST:(C#4.0模板)通过Windows身份验证安全并托管在Windows服务中吗?

[英]WCF REST : (C# 4.0 template) Securing with windows authentication and hosting in a windows service?

I am trying to find out how to secure my web services with Windows Authentication (Active Directory). 我试图找出如何使用Windows身份验证(Active Directory)保护我的Web服务。 I am using the "NEW" templates provided for c# 4.0 (vs 2010) and currently have this but i need to host it in a windows service - is this possible? 我正在使用为c#4.0(vs 2010)提供的“新”模板,目前有此模板,但是我需要将其托管在Windows服务中-这可能吗?

I thought the WCF Rest clientCredentialType ="Windows" actually uses IIS to provide this type of security? 我以为WCF Rest clientCredentialType =“ Windows”实际上使用IIS提供这种类型的安全性?

I have searched the internet and found many examples with C# 3.5 but none for the new template provided to vs 2010 C# 4.0 to create a rest service.W 我已经在互联网上搜索并找到了许多使用C#3.5的示例,但没有一个示例提供给vs 2010 C#4.0提供的用于创建休息服务的新模板。

<standardEndpoints>
  <webHttpEndpoint>
    <standardEndpoint name="" helpEnabled="true" 
                      automaticFormatSelectionEnabled="true">
      <security mode="">
        <transport clientCredentialType = "Windows" />
      </security>

New template in VS 2010 is called WCF REST Service application. VS 2010中的新模板称为WCF REST服务应用程序。 It creates web application with single predefined REST service which is exposed by ServiceRoute . 它使用ServiceRoute公开的单个预定义REST服务创建Web应用程序。 This application type is dependent on IIS hosting (or web server hosting generally) with AspNetCompatibility turned on. 此应用程序类型取决于启用了AspNetCompatibility IIS托管(或通常是Web服务器托管)。 It can't be directly converted into hosting in windows service. 它不能直接转换为Windows服务托管。 Some WCF REST features (WebRouting, Output chache profiles) are dependent on AspNetCompatibility which is normally not available outside of web server. 一些WCF REST功能(WebRouting,Output chache配置文件)取决于AspNetCompatibility ,通常在Web服务器外部不可用。

But If you don't need those features you can easily host WCF REST services in Windows service. 但是,如果您不需要这些功能,则可以在Windows服务中轻松托管WCF REST服务。 You can start new project as WCF service library and second project as Windows service to host services from library. 您可以将新项目作为WCF服务库启动,将第二个项目作为Windows服务启动以从库中托管服务。

You don't need any new template from .NET 4.0 to define WebHttp endpoint with windows security. 您不需要.NET 4.0中的任何新模板即可使用Windows安全性定义WebHttp端点。 This is enough: 这就够了:

<bindings>
  <webHttpBinding>
    <binding>
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </webHttpBinding>
</bindings>

By omitting name in binding element you are defining default webHttpBinding configuration. 通过在binding元素中省略name ,可以定义默认的webHttpBinding配置。 Each time you define endpoint with WebHttpBinding this configuration will be used. 每次使用WebHttpBinding定义终结点时,都会使用此配置。 StandardEnpoint is new feature of WCF 4.0. StandardEnpoint是WCF 4.0的新功能。 It can be also used for in this case but it is not necessary. 在这种情况下也可以使用它,但这不是必需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM