c# - 如何在 VS2010 内置 Web 服务器中使用 TransportWithMessageCredential 测试 WCF 服务

标签 c# wcf visual-studio-2010

我正在使用带有 basicHttpBinding 的自定义 UserNamePasswordValidator 开发 WCF 服务。但是,此配置仅适用于 HTTPS 绑定(bind)。由于 Visual Studio 2010 的内置 Web 服务器不支持 https,我该如何测试我的自定义验证器?我不断收到 Could not find a base address that matches scheme https for the endpoint with binding BasicHttpBinding。已注册的基址方案是 [http]. 错误,如果我将 clientCredentialType 设置为 none,则错误消失,但不会调用验证器。
以下是我的配置。

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name="ServiceErrorHandler" type="company.application.appserver.implementation.ServiceErrorHandlerBehaviorExtensionElement, AppSoftAppServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>
    </extensions>
    <bindings>
      <basicHttpBinding>
        <binding name="SimpleBinding">
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="DefaultBehavior" name="company.application.appserver.implementation.AppSoftUpdate">
        <endpoint address="udt" binding="basicHttpBinding" bindingConfiguration="SimpleBinding"
          name="AppSoftUpdate" bindingNamespace="http://company.application/update/2011/04"
          contract="company.application.appserver.interfaces.IAppSoftUpdate" />
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
          name="AppSoftUpdateMex" bindingNamespace="http://company.application/update/2011/04"
          contract="IMetadataExchange" />
      </service>
      <service behaviorConfiguration="DefaultBehavior" name="company.application.appserver.implementation.AppSoftTransaction">
        <endpoint address="udt" binding="basicHttpBinding" bindingConfiguration="SimpleBinding"
          name="AppSoftTransacao" bindingNamespace="http://company.application/transaction/2011/04"
          contract="company.application.appserver.interfaces.IAppSoftTransacao" />
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
          name="AppSoftTransacaoMex" bindingNamespace="http://company.application/transaction/2011/04"
          contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="DefaultBehavior">
          <serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding"
            httpGetBindingConfiguration="" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <ServiceErrorHandler />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom"
              customUserNamePasswordValidatorType=" company.application.appserver.implementation.AppSoftValidacaoLogin, AppSoftAppServer" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

最佳答案

使用 IIS 进行此测试。

打开您的项目属性,转到 Web 选项卡,点击 Use local IIS 单选按钮。本手册也适用于 VS2010:Using Visual Studio 2008 with IIS 7

如果尚未安装 IIS,请先安装:How to install IIS.

您的 Windows 版本需要高于 Windows Home。

您还需要为您的网站创建一个自签名证书。这在 IIS 7 中很容易做到:Self-Signed Certificates on IIS 7 – the Easy Way and the Most Effective Way

关于c# - 如何在 VS2010 内置 Web 服务器中使用 TransportWithMessageCredential 测试 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6089927/

相关文章:

c# - 具有角色的 WCF PrincipalPermission,为子方法配置

visual-studio-2010 - 无法在 Web 服务器上启动调试。启动的 URL 的 IIS 工作进程当前未运行

c# - C# 中的 typedef 等效于使用 C++ DLL

c# - 不重复的复杂排列

c# - 使用 DrawingContext.DrawText() 在 WPF 中绘制垂直文本

.net - 如何使用 HTTP Get 调用 WCF web 服务

c# - 如何在.NET Core中使用多个项目创建docker镜像?

c# - 是否可以在 WCF 中设置数据成员的最大长度

c# - 在 Visual Studio 中使用参数 Access 查询

c++ - Visual Studio 中的静态库与 DLL