c# - 使用 wshttpbinding 和用户名身份验证保护服务时,WCF 服务显示异常

标签 c# wcf workflow-foundation wcf-binding

我在.net 4.0中创建了一个工作流服务

我正在尝试保护此 (WCF) 服务,并使用以下链接来了解这是如何完成的。

我按照说明进行操作,但是当定义服务行为时,一切正常。 配置是这样的:

<behaviors>
      <serviceBehaviors>
        <behavior>
         <serviceCredentials name="ServiceBehavior">
            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
              membershipProviderName="AspNetSqlMembershipProvider" />
          </serviceCredentials>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

我的绑定(bind)是这样指定的:

<bindings>
      <wsHttpBinding>
        <binding name="CentralAdminBinding">
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="None"/>
            <message clientCredentialType="UserName"/>
            </security>
        </binding>
      </wsHttpBinding>
    </bindings>

当我调用 url 查看服务的 xamlx 时,显示以下错误:

找不到与绑定(bind) BasicHttpBinding 的端点的方案 https 相匹配的基地址。注册的基地址方案是[http]

我该如何处理这个错误?我根本不使用 https,但仍然收到错误。

我也尝试更改为 basichttpbinding 而不是 wshttp,但它给出了类似的错误。

将安全模式更改为消息时,出现以下错误:未提供服务证书。在ServiceCredentials中指定服务证书

有没有办法在没有证书的情况下使用配置?

最佳答案

TransportWithMessageCredential 表示您要使用传输安全性并在消息中发送凭据。在这种情况下,传输安全是指 HTTPS。 WCF 的首次发布要求用户名和密码只能用于安全通信。后来微软发布了补丁,允许解决避免 HTTPS 的问题,但仍然不建议这样做。在.NET 4.0中直接包含补丁。

如果您想在没有安全通信的情况下使用消息凭据,则必须创建与此类似的自定义绑定(bind):

<bindings>
  <customBinding>
    <binding name="HttpWithAuthentication">
      <security authenticationMode="UserNameOverTransport" allowInsecureTranpsort="true" />
      <context /> <!-- needed for durable worklfows -->
      <textMessageEncoding messageVersion="Soap12Addressing10" />
      <httpTransport />
    </binding>
  </customBinding>
</bindings>

allowInsecurTransport 的问题在于它是一些“快速修复”,并未与所有 WCF 功能集成。例如,当您使用它时,您的服务无法生成 WSDL/元数据,因为这部分仍然需要安全通信。

关于c# - 使用 wshttpbinding 和用户名身份验证保护服务时,WCF 服务显示异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3879935/

相关文章:

c# - 解码 git 对象/"Block length does not match with its complement"错误

.net-4.0 - Windows Workflow Foundation 3.5 中创建的状态机是否与版本 4.0 兼容?

workflow - 高吞吐量和 Windows Workflow Foundation

c# - 如何在像 Office 2010 这样的 WPF 应用程序中对 Aero 玻璃进行渐变淡入淡出?

c# - WPF DataGrid列总MVVM模式

c# - C# 中的 BringToFront()

wcf - Windows Mobile 开发 - 从哪里开始?

wcf - WCF 服务应该返回 EntityObject 还是 POCO/DTO 类?

c# - 如何从 WCF 获取数据(异步)?