WCF 第四章 绑定 使用基础Web Services

Web 服务时异构系统间相互通信的基础。比如,基于JAVA平台创建的IBM Websphere或者BEA WebLogic服务必须与基于.NET 平台创建的客户端和服务端进行无缝连接。基于.NET平台创建的服务必须与基于JAVA平台创建的客户端和服务端进行无缝连接。在WCF出现之 前,ASP.NET Web 服务(ASMX)和高级Web 服务在.NET平台上提供了这种能力。在.NET 3.0时,WCF直接取代了这些技术并提供了一个单独的统一的架构来创建Web 服务。WCF包括了很多种暴露交互式Web 服务的绑定,包括basicHttpBinding, wsHttpBinding, wsDualHttpBinding和wsFederationHttpBinding绑定。

在这一章节,我们检查basicHttpBinding绑定,它提供对基于WS- I 基础协议1.1 Web 服务的支持。截至2007年,WS-I 基础协议1.1 覆盖了大多数广泛的基于Web 服务协议的部署而且是最大多开发人员所熟悉的Web服务。其他的基于Web 服务的绑定会稍后在”使用高级Web 服务通信”章节中介绍,同时也会在本书的第八章讨论。

basicHttpBinding

basicHttpBinding 绑定提供对基于WS-I 基础协议1.1(WS-BP 1.1)标准的Web 服务通信的支持。这包括比如SOAP 1.1, WSDL 1.1 和消息安全1.0(包括X.509和用户名令牌协议v1.0)。WS-BP 1.1 标准早在2004年就已经指定。尽快basicHttpBinding绑定提供异构系统的交互通信,它不提供对最新的Web 服务标准比如事务和可信赖消息的支持。basicHttpBinding绑定意味着要与使用基于WS-BP 1.1 标准的Web 服务的应用程序一起使用,比如ASP.NET ASMX Web 服务。

注意 创建基于最新标准的服务

basicHttpBinding绑定意味着要与先前基于ASP.NET技术的遗留Web 服务一起工作。这也就是说basicHttpBinding绑定默认配置为使用原有标准,比如SOAP 1.1.basicHttpBinding绑定也是唯一的默认情况下不采用安全机制的绑定。如果你需要创建新的Web 服务,我们建议使用ws2007HttpBinding绑定,因为它配置为使用新的标准而且默认支持安全性。

下面的代码显示了basicHttpBinding绑定的地址格式:

http://{hostname}[:port]/{service location}

https://{hostname}[:port]/{service location}

Http协议默认端口是80, Https默认端口是443。这是任何基于HttpTransportBindingElement绑定元素的绑定情况。最常用的方式是使用https来获得安全的basicHttpBinding绑定,使用SSL/TLS加密。

表4.5 列出了在basicHttpBinding绑定上可以设置的属性。

表4.5 basicHttpBinding 绑定属性

下面的配置信息用来与列表4.2到4.4中的样例一起使用。列表4.11中的配置信息使用basicHttpBinding绑定暴露StockQuoteService服务。

列表4.11 basicHttpBinding 宿主配置

01<?xml version="1.0" encoding="utf-8" ?>
02<configuration>
03    <system.serviceModel>
04        <services>
05            <service behaviorConfiguration="" name="EssentialWCF.StockQuoteService">
06                <endpoint binding="basicHttpBinding" bindingConfiguration=""
07                    contract="EssentialWCF.IStockQuoteService" />
08                <host>
09                    <baseAddresses>
10                        <add baseAddress="http://localhost/stockquoteservice" />
11                    </baseAddresses>
12                </host>
13            </service>
14        </services>
15    </system.serviceModel>
16</configuration>

列表4.12 显示了调用列表4.11中使用basicHttpBinding绑定的服务的客户端配置信息。

列表4.12 basicHttpBinding客户端配置

01<?xml version="1.0" encoding="utf-8" ?>
02<configuration>
03    <system.serviceModel>
04        <services>
05            <service behaviorConfiguration="" name="EssentialWCF.StockQuoteService">
06                <endpoint binding="basicHttpBinding" bindingConfiguration=""
07                    contract="EssentialWCF.IStockQuoteService" />
08                <host>
09                    <baseAddresses>
10                        <add baseAddress="http://localhost/stockquoteservice" />
11                    </baseAddresses>
12                </host>
13            </service>
14        </services>
15    </system.serviceModel>
16</configuration>


========

转载自

 

posted @ 2011-06-29 10:16  Gavin Liu  阅读(168)  评论(0编辑  收藏  举报

Right people get the right information at the right time.
以技术求生存,以市场求发展;学以至用,开拓创新;达技术之颠峰,至市场之广阔!