.net - 不使用证书保护 WCF WebService

标签 .net wcf web-services security wcf-security

几天来我一直在尝试正确保护我的 WCF WebService,但现在遇到了障碍。我尝试在不使用证书的情况下保护此 WebService,因为它将在安全的 Intranet 内运行。

我希望能够通过用户名/密码保护 WebService,而无需更改验证用户名和密码的每种方法,也无需使用证书。这可能吗:

我当前的 web.config 如下:

<?xml version="1.0"?>
<configuration>
 <system.web>
  <compilation debug="true" targetFramework="4.0" />
 </system.web>
 <system.serviceModel>
  <services>
   <service name="TestWS.Service1" behaviorConfiguration="Default">
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    <endpoint contract="TestWS.IService1" binding="wsHttpBinding" bindingConfiguration="Binding1" address="" />
  </service>
 </services>
 <bindings>
  <wsHttpBinding>
    <binding name="Binding1">
      <security mode="Message">
       <message clientCredentialType="UserName"/>
      </security>
    </binding>
  </wsHttpBinding>
 </bindings>
 <behaviors>
  <serviceBehaviors>
    <behavior name="Default">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="TestWS.Validation.VanguardValidator, TestWS" />
      </serviceCredentials>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
   </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
 </system.serviceModel>
 <system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
 </system.webServer>
</configuration>

提前致谢,

帕特里克

最佳答案

如果您使用用户名/密码验证,您可能会在消息中以纯文本形式发送凭据。因此,您要么需要使用传输级 (SSL) 安全性 (https://....),要么您必须在服务器端拥有证书来提供共享的方式Secret 以便客户端和服务器之间的消息可以被加密和签名。或者,如果您根本不需要任何东西,也可以完全关闭安全性。

参见Fundamentals of WCF Security有关 WCF 安全性的精彩介绍,请访问 MSDN docs on Programming WCF Security ,或 Juval Löwy 关于 Declarative WCF Security 的优秀 MSDN 文章

关于.net - 不使用证书保护 WCF WebService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5196828/

相关文章:

c# - WCF,StackOverflowException

web-services - JAX-WS 更改 WebParam 的命名空间

java - 限制 Web 服务访问内部 IP 地址

c# - 在 Rider 和 Visual Studio 中使用 C# 和 ASP.Net 的 Git 问题

c# - 如何检查实体是否是 foreach 循环的第一个元素

c# - 如何在不等待的情况下在 Singleton 中执行昂贵的操作?

web-services - 在 laravel/lumen 中使用客户端 ID 和 key 访问 API

c# - Visual Studio 忽略输出文件夹中的 PDB 文件(来自 NUGET 包)

c# - 如何在 RabbitMQ 上实现非阻塞?

c# - 如何在 ASP.Net MVC 应用程序中使用来自 WCF 身份验证服务的身份验证 cookie