美文网首页asp.net
WCF(一)---简化功能(WCF Simplification

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

作者: 玩伴_Cocoa | 来源:发表于2016-11-14 17:53 被阅读85次

    简化了配置文件

    当在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

    流的改进

    • WCF新增加了支持异步流。为了实现异步流,需要在服务宿主中添加终结点DispatcherSynchronizationBehavior,并且将AsynchronousSendEnabled属性设置为true。当多个客户端在这个服务读取流时会有所帮助。这样WCF不会阻塞一个客户端线程。
    • 当用IIS托管服务的时候,删除了缓存消息的限制。在以前的WCF版本中,当IIS服务器接收到消息时(用流消息传输),ASP.NET会将整个消息在发给WCF之前缓存下来,这样讲消耗掉大量内存。这个缓存机制在.NET4.5被取消,现在IIS托管的WCF服务可以在信息未完全接受完之前进行处理,从而实现真正的流,这使WCF响应更快,并且提高了性能。另外,不需要设置maxRequestLength,如果设置了,也会被忽略掉。更多有关maxRequestLength的信息请参考:http运行时元素配置(<httpRuntime> configuration element),还需要配置maxAllowedContentLength,更多信息参考:IIS请求限制(IIS Request Limits)

    相关文章

      网友评论

        本文标题:WCF(一)---简化功能(WCF Simplification

        本文链接:https://www.haomeiwen.com/subject/xxohpttx.html