我正在研究用.Net 4.5.1编写的客户端软件。该软件支持调用不同的Web服务,其中一些是由WS-Security保护的,其中一些不是。
我有什么方法可以发送一些嵌入了WS-Security的请求,有些请求不是吗?
非常感谢
答案 0 :(得分:0)
您调用的每个服务在应用程序的配置文件中都有自己的配置部分。
以下是从the MSDN article 'Client Configuration'复制的示例app.config
。请注意您调用的每个服务如何具有endpoint
元素,并且每个endpoint
元素都可以引用binding
个配置。 WS-security配置在绑定元素上完成,有关WCF安全性的文档,请参阅here。基本上,您必须将安全模式设置为Message
才能使用请求和响应的WS安全加密。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<client>
<endpoint
name="endpoint1"
address="http://localhost/ServiceModelSamples/service.svc"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IHello"
behaviorConfiguration="IHello_Behavior"
contract="IHello" >
<metadata>
<wsdlImporters>
<extension
type="Microsoft.ServiceModel.Samples.WsdlDocumentationImporter, WsdlDocumentation"/>
</wsdlImporters>
</metadata>
<identity>
<servicePrincipalName value="host/localhost" />
</identity>
</endpoint>
// Add another endpoint by adding another <endpoint> element.
<endpoint
name="endpoint2">
//Configure another endpoint here.
</endpoint>
</client>
//The bindings section references by the bindingConfiguration endpoint attribute.
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IHello"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard">
<readerQuotas maxDepth="32"/>
<reliableSession ordered="true"
enabled="false" />
<security mode="Message">
//Security settings go here.
</security>
</binding>
<binding name="Another Binding"
//Configure this binding here.
</binding>
</wsHttpBinding>
</bindings>
//The behavior section references by the behaviorConfiguration endpoint attribute.
<behaviors>
<endpointBehaviors>
<behavior name=" IHello_Behavior ">
<clientVia />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>