![](/img/trans.png)
[英]How to get SoapUI to work with ws-security mode 'TransportWithMessageCredential'
[英]How to authenticate wsdl get with TransportWithMessageCredential security mode for the endpoint?
我有一个 WCF 端点,它公开了一个带有basicHttpBinding
的 API 。 此投标设置为对clientCredentialType
使用安全模式TransportWithMessageCredentialand
和UserName
。
因为安全性是在消息级别实现的,所以在 WCF 中,IIS 需要允许匿名访问。 因此,无需提供任何凭据即可获得 wsdl。
如何强制认证以获取服务元数据?
这里当前的服务配置看起来像(来自 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>
我尝试了显而易见的方法,通过使用服务行为配置为元数据设置特定绑定:
<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>
但不支持。 它抛出这个:
MessageVersion 'Soap11 ( http://schemas.xmlsoap.org/soap/envelope/ ) AddressingNone ( http://schemas.microsoft.com/ws/2005/05/addressing/none )'在此方案中不受支持。 仅支持 MessageVersion 'EnvelopeNone ( http://schemas.microsoft.com/ws/2005/05/envelope/none ) AddressingNone ( http://schemas.microsoft.com/ws/2005/05/'addressing ) .
我不明白这个错误或如何解决它。
通常我们不会在生产环境中公开我们的元数据,但是如果你想启用元数据,我们可以使用 https 绑定来保护元数据。
1.使用适当的 X.509 证书配置端口。 证书必须来自受信任的权威机构,并且必须具有“服务授权”的预期用途。 您必须使用 HttpCfg.exe 工具将证书附加到端口。
2.创建 ServiceMetadataBehavior class 的新实例。
3.将ServiceMetadataBehavior class的HttpsGetEnabled属性设置为true。
4.将 HttpsGetUrl 属性设置为适当的 URL。 请注意,如果您指定绝对地址,则 URL 必须以方案 https:// 开头。 如果指定相对地址,则必须为服务主机提供 HTTPS 基地址。 如果不设置该属性,则默认地址为“”,或者直接在HTTPS基地址为服务。
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();
这是在 WCF 上启用的身份验证,您也可以在 IIS 上启用 windows 身份验证,这两种方法都可以保护元数据。
但是在生产环境中,我不建议你开启元数据,因为这样会导致元数据泄露的风险。WCF服务的调用也可以通过通道工厂来调用。 在这种情况下,我们可以在不知道服务器元数据的情况下调用 WCF 服务。
有关如何保护元数据的更多信息,您可以参考此链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.