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

发布于 2024-11-09 00:33:15 字数 3416 浏览 0 评论 0原文

我正在使用带有 basicHttpBinding 的自定义 UserNamePasswordValidator 开发 WCF 服务。但是,此配置仅适用于 HTTPS 绑定。由于 Visual Studio 2010 的内置 Web 服务器不支持 https,我如何测试我的自定义验证器?我不断收到无法找到与绑定 BasicHttpBinding 的端点的方案 https 相匹配的基地址。注册的基地址方案是 [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>

I'm developing a WCF Service with a custom UserNamePasswordValidatorwith a basicHttpBinding. This configuration, however, works only on HTTPS binding. Since Visual Studio 2010's built in web server does not support https, how can I test my custom validator? I keep getting Could not find a base address that matches scheme https for the endpoint with binding BasicHttpBinding. Registered base address schemes are [http]. error and, if I set the clientCredentialType to none, the error is gone, but the validator does not get called.
Below is my configuration.

<?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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

很酷又爱笑 2024-11-16 00:33:15

使用 IIS 进行此测试。

打开项目属性,转到 Web 选项卡,点击使用本地 IIS 单选按钮。本手册也适用于 VS2010: 将 Visual Studio 2008 与 IIS 7 结合使用

如果尚未安装 IIS,请先安装它:如何安装 IIS。< /a>

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

您还需要为您的网站创建自签名证书。这在 IIS 7 中很容易做到:IIS 7 上的自签名证书 – 最简单且最有效的方法

Use IIS for this testing.

Open your project properties, go to the Web tab, hit Use local IIS radio button. This manual is valid for VS2010 too: Using Visual Studio 2008 with IIS 7

If IIS is not installed yet, install it first: How to install IIS.

You need to have Windows edition higher than Windows Home.

You will also need to create a self-signed certificate for your web site. This is easy to do in IIS 7: Self-Signed Certificates on IIS 7 – the Easy Way and the Most Effective Way

雾里花 2024-11-16 00:33:15

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

You cannot test such WCF service in Cassine (built-in web server in VS 2010). You must use local IIS or install VS 2010 SP1 and download IIS Express which is lightweight web server for development (can replace Cassini in VS and supports HTTPS with self signed certificates). IIS Express doesn't need any specific Windows edition and it works on all versions since Windows XP but it provides same features as IIS 7.5.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文