asp.net

WCF(一)---简化功能(WCF Simplification

2016-11-14  本文已影响85人  玩伴_Cocoa

简化了配置文件

当在Visual Studio 添加服务引用或者用SvcUtil.exe(配置文件客户端)工具生成的时候,在以前的WCF版本中,这些配置文件包含了所有的绑定属性即使它是默认值。在WCF的4.5版本以后,这些配置文件只包含设置过的非默认值的属性。

WCF 3.0 以前配置文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" 
                    hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" 
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" 
                        maxArrayLength="16384" maxBytesPerRead="4096"
                        maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:36906/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="IService1"
                name="BasicHttpBinding_IService1" />
        </client>
    </system.serviceModel>
</configuration>

WCF 4.5以后配置文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService1" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:36906/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="IService1"
                name="BasicHttpBinding_IService1" />
        </client>
    </system.serviceModel>
</configuration>

契约优先开发模式

现在WCF支持契约优先开发模式。svcutl.exe工具包含一个服务契约转换按钮,允许你来选择从WSDL生成服务或者数据契约。

从一个可移植的子集项目中添加服务引用

可移植的子集项目可以让开发者在支持多个平台(desktop, Silverlight, Windows Phone, and XBOX)的同时维护一个资源树和生成系统。可移植的子集项目仅引用了.NET可移植库,它是一个可以在任何.NET平台使用的框架。开发者可以按照添加WCF客户端应用程序的方法来添加一个服务引用。更多信息请参考:从一个可移植的子集项目中添加服务引用

ASP.NET兼容模式默认的改变

ASP.NET兼容模式可以让开发者获得管道的全部功能。使用兼容模式时 ,必须在web.config文件中将<serviceHostingEnvironment>节点下的aspNetCompatibilityEnabled属性设置为true,另外,在应用程序域中所有的服务必须有RequirementsMode属性,并且将AspNetCompatiliblityRequirementsAttribute设置为Allowed或者Required,默认AspNetCompatiliblityRequirementsAttribute值为Allowed,并且WCF服务应用模板将aspNetCompatibilityEnabled设置为true.更多信息请参考:WCF中的新功能WCF服务和ASP.NET

流的改进

上一篇下一篇

猜你喜欢

热点阅读