由於CSLA數據門戶支持WCF代理,所以這裡我就很自然的使用了WCFProxy功能來作為分布式應用支持。在園子中有很多人對WCF如何使用都進行了細致的介紹,而且本人其實也只是了解WCF的皮毛而已,所以我這裡就不作具體介紹,大家想從整體上了解如何使用WCF的可以上網去搜索一下。
由於CSLA內置了WCF數據門戶,所以在使用過程中只需要在服務器端和客戶端進行簡單配置既能夠簡單使用了。由於應用中可能會傳輸較大數據,所以會對修改一些配置以及添加壓縮數據功能。本篇主要講解一下與OpenExpressApp相關的WCF知識。
服務器端配置
在serviceModel中添加端口以及綁定、擴展等配置。下面配置為支持http和net.tcp協議。其中對一些參數進行了配置,如maxReceivedMessageSize等為了支持大數據量進行了配置。
<system.serviceModel>
<services>
<!-- Before deployment, you should remove the returnFaults behavior configuration to avoid disclosing information in exception messages -->
<service name="Csla.Server.Hosts.WcfPortal" behaviorConfiguration="returnFaults">
<endpoint address="http://localhost:8000/GIX4" binding ="customBinding" bindingConfiguration="compactBinding" contract="Csla.Server.Hosts.IWcfPortal"/>
<endpoint address="net.tcp://localhost:8001/GIX4" binding="netTcpBinding" bindingConfiguration="netTcp" contract="Csla.Server.Hosts.IWcfPortal">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/GIX4"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<customBinding>
<binding name="compactBinding" sendTimeout="00:10:00">
<compactMessageEncoding>
<binaryMessageEncoding>
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
</binaryMessageEncoding>
</compactMessageEncoding>
<httpTransport maxReceivedMessageSize="2147483647" />
</binding>
</customBinding>
<netTcpBinding>
<binding name="netTcp" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
</binding>
</netTcpBinding>
</bindings>
<extensions>
<bindingElementExtensions>
<add name="compactMessageEncoding" type="Amib.WCF.CompactMessageEncodingElement, CompactMessageEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bindingElementExtensions>
</extensions>
</system.serviceModel>
客戶端配置
首先在aPPSetting中添加CslaDataPortalProxyKey為Csla.DataPortalClIEnt.WcfProxy, Csla,指定使用WCF數據門戶
<aPPSettings>
<add key="CslaAuthentication" value="Csla" />
<add key="CslaPropertyChangedMode" value="Xaml" />
<add
key="CslaDataPortalProxy" value="Csla.DataPortalClIEnt.WcfProxy, Csla"/
</aPPSettings>
然後再在serviceModel中添加端口以及綁定、擴展等配置,這些都與服務器端配置對應。下面配置為支持http協議,你也可以配置為支持net.tcp協議,但好像CSLA中一次只能指定一個。
<serviceModel>
<!--<clIEnt>
<endpoint name="WcfDataPortal"
address="net.tcp://localhost:8001/GIX4"
binding="netTcpBinding" bindingConfiguration="netTcp"
contract="Csla.Server.Hosts.IWcfPortal"/>
</clIEnt>-->
<clIEnt>
<endpoint name="WcfDataPortal" address="http://localhost:8000/GIX4" binding="customBinding" bindingConfiguration="compactBinding" contract="Csla.Server.Hosts.IWcfPortal" />
</clIEnt>
<bindings>
<customBinding>
<binding name="compactBinding" sendTimeout="00:10:00">
<compactMessageEncoding>
<binaryMessageEncoding>
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binaryMessageEncoding>
</compactMessageEncoding>
<httpTransport maxReceivedMessageSize="2147483647" />
</binding>
</customBinding>
<netTcpBinding>
<binding name="netTcp" transferMode="Streamed" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</netTcpBinding>
</bindings>
<extensions>
<bindingElementExtensions>
<add name="compactMessageEncoding" type="Amib.WCF.CompactMessageEncodingElement, CompactMessageEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bindingElementExtensions>
</extensions>
</system.serviceModel>