【问题标题】:How to test WCF service with TransportWithMessageCredential in VS2010 built-in web server如何在 VS2010 内置 Web 服务器中使用 TransportWithMessageCredential 测试 WCF 服务
【发布时间】:2011-05-22 18:35:56
【问题描述】:

我正在开发一个带有自定义 UserNamePasswordValidator 和 basicHttpBinding 的 WCF 服务。但是,此配置仅适用于 HTTPS 绑定。由于 Visual Studio 2010 的内置 Web 服务器不支持 https,我如何测试我的自定义验证器?我不断收到 Could not find a base address that matches scheme https for the endpoint with binding BasicHttpBinding. Registered base address schemes are [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>

【问题讨论】:

    标签: c# wcf visual-studio-2010


    【解决方案1】:

    使用 IIS 进行此测试。

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

    如果还没有安装IIS,请先安装:How to install IIS.

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

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

    【讨论】:

      【解决方案2】:

      您无法在 Cassine(VS 2010 中的内置 Web 服务器)中测试此类 WCF 服务。您必须使用本地 IIS 或安装 VS 2010 SP1 和 download IIS Express,这是用于开发的轻量级 Web 服务器(can replace Cassini in VS 并支持带有自签名证书的 HTTPS)。 IIS Express 不需要任何特定的 Windows 版本,它适用于自 Windows XP 以来的所有版本,但它提供与 IIS 7.5 相同的功能。

      【讨论】:

      • 感谢您的回答。 @Alex's 更详细一点,所以我将他标记为答案,但你的也有很大帮助,所以我给每个人投了 1 票。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      • 2013-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-01
      • 1970-01-01
      相关资源
      最近更新 更多