WCF REST:(C#4.0模板)确保与Windows身份验证和托管在Windows服务?身份验证、模板、REST、WCF

2023-09-08 13:29:21 作者:蝴蝶亲吻猫

我试图找出如何使用Windows身份验证(Active Directory)的保护我的Web服务。我使用提供了C#4.0(VS 2010),新的模板,目前拥有这一点,但我需要它托管在Windows服务 - 这是可能的。

我认为WCF休息clientCredentialType =窗口实际上使用IIS来提供这种类型的安全?

我在网上搜索,发现许多例子用C#3.5,但没有新模板VS 2010 C#4.0创建了休息service.W提供

 < standardEndpoints>
  < webHttpEndpoint>
    < standardEndpoint NAME =helpEnabled =真
                      automaticFormatSelectionEnabled =真正的>
      <安全模式=>
        <交通运输clientCredentialType =的Windows/>
      < /安全>
 

解决方案

在VS 2010中新的模板被称为WCF REST服务应用程序。它创建Web应用程序pdefined单$ P $ REST服务,这是由 ServiceRoute 曝光。此应用程序的类型依赖于IIS托管(或Web服务器通常主机)与 AspNetCompatibility 打开。它不能直接转换为托管在Windows服务。一些WCF休息功能(WebRouting,输出chache配置文件)都依赖于 AspNetCompatibility 这通常是不可用之外的Web服务器。

不过,如果你并不需要这些功能,你可以很容易地在Windows服务主机WCF REST服务。你可以开始新的项目作为WCF服务库和第二个项目作为Windows服务从图书馆举办的服务。

WCF4.0 – RESTful WCF Services .net 火龙果软件工程

您不必从.NET 4.0的任何新模板来定义WebHttp端点与Windows的安全性。这是不够的:

 <绑定>
  <的WebHttpBinding>
    <结合>
      <安全模式=TransportCredentialOnly>
        <交通运输clientCredentialType =的Windows/>
      < /安全>
    < /装订>
  < /的WebHttpBinding>
< /绑定>
 

由于省略名称结合元素正在定义默认的WebHttpBinding 配置。每次定义端点的WebHttpBinding 时该配置将被使用。 StandardEnpoint 是WCF 4.0的新功能。它也可以用于在此情况下,但它不是必需的。

I am trying to find out how to secure my web services with Windows Authentication (Active Directory). 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?

I thought the WCF Rest clientCredentialType ="Windows" actually uses IIS to provide this type of security?

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

<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. It creates web application with single predefined REST service which is exposed by ServiceRoute. This application type is dependent on IIS hosting (or web server hosting generally) with AspNetCompatibility turned on. It can't be directly converted into hosting in windows service. Some WCF REST features (WebRouting, Output chache profiles) are dependent on AspNetCompatibility which is normally not available outside of web server.

But If you don't need those features you can easily host WCF REST services in Windows service. You can start new project as WCF service library and second project as Windows service to host services from library.

You don't need any new template from .NET 4.0 to define WebHttp endpoint with windows security. 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. Each time you define endpoint with WebHttpBinding this configuration will be used. StandardEnpoint is new feature of WCF 4.0. It can be also used for in this case but it is not necessary.