简体   繁体   English

如何使用端点的 TransportWithMessageCredential 安全模式对 wsdl 进行身份验证?

[英]How to authenticate wsdl get with TransportWithMessageCredential security mode for the endpoint?

I have a WCF endpoint that exposes a API with a basicHttpBinding .我有一个 WCF 端点,它公开了一个带有basicHttpBinding的 API 。 This biding is set to use security mode TransportWithMessageCredentialand UserName for clientCredentialType .此投标设置为对clientCredentialType使用安全模式TransportWithMessageCredentialandUserName

Because security is implemented at message level, at the WCF, the IIS needs to allow anonymous access.因为安全性是在消息级别实现的,所以在 WCF 中,IIS 需要允许匿名访问。 And so, wsdl can be obtain without providing any credentials.因此,无需提供任何凭据即可获得 wsdl。

How to force authentication to get the service metadata?如何强制认证以获取服务元数据?

Here the current service configuration looks like (from web.config)这里当前的服务配置看起来像(来自 web.config)

<system.serviceModel> 
  <bindings>
    <basicHttpBinding>
      <binding name="secure">
        <security mode="TransportWithMessageCredential">
          <message clientCredentialType="UserName" />
        </security>   
      </binding>     
      </basicHttpBinding>
  </bindings>
  <services>
    <service behaviorConfiguration="secure" name="someProject.MyService">
      <endpoint  binding="basicHttpBinding" contract="someProject.IService" bindingConfiguration="secure"  />   
    </service>
  </services>
  <behaviors>    
    <serviceBehaviors>
        <behavior name="secure">          
        <serviceMetadata httpsGetEnabled="true"  />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

I try the obvious, to set a specific binding for the metatada, by using service behavior configuration:我尝试了显而易见的方法,通过使用服务行为配置为元数据设置特定绑定:

<behavior name="secure">          
   <serviceMetadata httpsGetEnabled="true" httpsGetBinding="basicHttpBinding" httpsGetBindingConfiguration="transportSecure" />
</behavior>

//and add the new binding    
  <basicHttpBinding>
      <binding name="transportSecure">
        <security mode="Transport">
          <message clientCredentialType="UserName" />
        </security>
      </binding>
    </basicHttpBinding>

But it is not supported.但不支持。 It throws this:它抛出这个:

MessageVersion 'Soap11 ( http://schemas.xmlsoap.org/soap/envelope/ ) AddressingNone ( http://schemas.microsoft.com/ws/2005/05/addressing/none )' is not supported in this scenario. MessageVersion 'Soap11 ( http://schemas.xmlsoap.org/soap/envelope/ ) AddressingNone ( http://schemas.microsoft.com/ws/2005/05/addressing/none )'在此方案中不受支持。 Only MessageVersion 'EnvelopeNone ( http://schemas.microsoft.com/ws/2005/05/envelope/none ) AddressingNone ( http://schemas.microsoft.com/ws/2005/05/addressing/none )' is supported.仅支持 MessageVersion 'EnvelopeNone ( http://schemas.microsoft.com/ws/2005/05/envelope/none ) AddressingNone ( http://schemas.microsoft.com/ws/2005/05/'addressing ) .

I don't understand this error or how to get around it.我不明白这个错误或如何解决它。

Normally we will not disclose our metadata in the production environment,But if you want to enable metadata, we can use https binding to protect the metadata.通常我们不会在生产环境中公开我们的元数据,但是如果你想启用元数据,我们可以使用 https 绑定来保护元数据。

1.Configure a port with an appropriate X.509 certificate. 1.使用适当的 X.509 证书配置端口。 The certificate must come from a trusted authority, and it must have an intended use of "Service Authorization."证书必须来自受信任的权威机构,并且必须具有“服务授权”的预期用途。 You must use the HttpCfg.exe tool to attach the certificate to the port.您必须使用 HttpCfg.exe 工具将证书附加到端口。

2.Create a new instance of the ServiceMetadataBehavior class. 2.创建 ServiceMetadataBehavior class 的新实例。

3.Set the HttpsGetEnabled property of the ServiceMetadataBehavior class to true. 3.将ServiceMetadataBehavior class的HttpsGetEnabled属性设置为true。

4.Set the HttpsGetUrl property to an appropriate URL. 4.将 HttpsGetUrl 属性设置为适当的 URL。 Note that if you specify an absolute address, the URL must begin with the scheme https://.请注意,如果您指定绝对地址,则 URL 必须以方案 https:// 开头。 If you specify a relative address, you must supply an HTTPS base address for your service host.如果指定相对地址,则必须为服务主机提供 HTTPS 基地址。 If this property is not set, the default address is "", or directly at the HTTPS base address for the service.如果不设置该属性,则默认地址为“”,或者直接在HTTPS基地址为服务。

5.Add the instance to the behaviors collection that the Behaviors property of the ServiceDescription class returns, as shown in the following code. 5.将该实例添加到ServiceDescription class的Behaviors属性返回的行为集合中,如下代码所示。

ServiceMetadataBehavior sb = new ServiceMetadataBehavior();
sb.HttpsGetEnabled = true;
sb.HttpsGetUrl = new Uri("https://myMachineName:8036/myEndpoint");
myServiceHost.Description.Behaviors.Add(sb);

myServiceHost.Open();

This is authentication enabled on WCF, you can also enable windows authentication on IIS, both methods can protect metadata.这是在 WCF 上启用的身份验证,您也可以在 IIS 上启用 windows 身份验证,这两种方法都可以保护元数据。

But in the production environment, I do not recommend that you enable metadata, because this will lead to the risk of metadata leakage.The call of WCF service can also be called through the channel factory.但是在生产环境中,我不建议你开启元数据,因为这样会导致元数据泄露的风险。WCF服务的调用也可以通过通道工厂来调用。 In this case, we can call WCF service without knowing the metadata of the server.在这种情况下,我们可以在不知道服务器元数据的情况下调用 WCF 服务。

For more information on how to protect metadata, you can refer to this link:有关如何保护元数据的更多信息,您可以参考此链接:

https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-secure-metadata-endpoints?redirectedfrom=MSDN https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-secure-metadata-endpoints?redirectedfrom=MSDN

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使SoapUI与ws安全模式“ TransportWithMessageCredential”一起使用 - How to get SoapUI to work with ws-security mode 'TransportWithMessageCredential' WCF安全模式TransportWithMessageCredential - WCF Security Mode TransportWithMessageCredential 使用TransportWithMessageCredential安全模式在wsHttpBinding中配置MaxClockSkew - Configure MaxClockSkew in wsHttpBinding with TransportWithMessageCredential Security Mode WCF安全性:TransportWithMessageCredential和消息安全模式之间的区别 - WCF Security: Difference between TransportWithMessageCredential and Message Security Mode WCF安全模式是使用UserName的TransportWithMessageCredential,在哪里验证? - WCF security mode is TransportWithMessageCredential using UserName, where to validate? 使用TransportWithMessageCredential安全模式的basicHttpBinding的等效自定义WCF绑定 - Equivalent custom WCF binding for basicHttpBinding with TransportWithMessageCredential security mode 具有安全模式TransportWithMessageCredential的pollingDuplexHttpBinding。 来自服务器的响应未到达客户端 - pollingDuplexHttpBinding with security mode TransportWithMessageCredential. response from server don't come to client 连接到安全模式 =“无”的 basicHttpBinding 端点时出现问题 - Problems connecting to a basicHttpBinding endpoint with security mode=“None” 如何为wsdl:port配置WCF端点 - How To Configure WCF Endpoint For a wsdl:port WCF 4-使用X.509证书进行传输和消息安全的TransportWithMessageCredential - WCF 4 - TransportWithMessageCredential using X.509 certificates for transport and message security
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM