首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动态调用受WS-Security保护的web服务

动态调用受WS-Security保护的web服务
EN

Stack Overflow用户
提问于 2015-10-22 00:12:13
回答 1查看 44关注 0票数 1

我正在开发一个用.Net 4.5.1编写的客户端软件。该软件支持调用不同的web服务,其中有些是由WS-Security保护的,有些则不是。

有没有什么方法可以发送嵌入了WS-Security的请求,而不是嵌入WS-Security的请求?

非常感谢

EN

回答 1

Stack Overflow用户

发布于 2015-10-23 19:59:48

您调用的每个服务在应用程序的配置文件中都有自己的配置节。

下面是从the MSDN article 'Client Configuration'复制的示例app.config。请注意,您调用的每个服务都有一个endpoint元素,并且每个endpoint元素都可以引用binding配置。WS-security配置是在绑定元素上完成的,有关here安全性的文档,请参阅WCF。基本上,您必须将安全模式设置为Message,才能对请求和响应使用WS-security加密。

代码语言:javascript
复制
<?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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33264264

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档