日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

Spring.NET 1.3.1 新特性探索系列2——WCF命名空间解析器

發(fā)布時間:2024/4/15 asp.net 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring.NET 1.3.1 新特性探索系列2——WCF命名空间解析器 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

  

  Spring.NET對分布式程序的支持是有目共睹的。在1.3.1之前的版本,對Remoting和Webservice支持的很好,并且有其對應(yīng)的解析器,但對WCF支持的不是很完美。然而1.3.1版本加入了WCF的命名空間解析器功能。我們導入?xmlns:wcf="http://www.springframework.net/wcf“? 命名空間后,便可以使用解析器提供的配置了。

?

  一、新建一個WCF契約程序集:WcfContract。

  建立接口ISpringContract

  

namespace?WcfContract
{
????[ServiceContract]
????
public?interface?ISpringContract
????{
????????[OperationContract]
????????
string?GetData(int?value);
????}
}

?

?

?

  二、建立WCF的服務(wù)器端項目WcfServer。

  新建SpringService.svc文件,其SpringService類繼承ISpringContract

  

SpringService namespace?WcfServer
{
????
public?class?SpringService?:?ISpringContract
????{
????????
public?string?GetData(int?value)
????????{
????????????
return?string.Format("你輸入的是:?{0}",?value);
????????}

??????
????}
}

?

?  三、建立WCF客戶端項目WcfClient

  配置app.config

  

app.config <?xml?version="1.0"?>
<configuration>
??
??
<configSections>
????
<sectionGroup?name="spring">
??????
<section?name="context"?type="Spring.Context.Support.ContextHandler,?Spring.Core"/>
??????
<section?name="objects"?type="Spring.Context.Support.DefaultSectionHandler,?Spring.Core"/>
????
</sectionGroup>
??
</configSections>

??
<spring>
????
<context>
??????
<resource?uri="assembly://WcfClient/WcfClient.Config/Wcf.xml"/>
????
</context>
??
</spring>
??
??
<system.serviceModel>
????????
<bindings>
??????????????
<basicHttpBinding>
????????????????????
<binding?name="BasicHttpBinding_ISpringContract"?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:50784/SpringService.svc"
????????????????????binding
="basicHttpBinding"?bindingConfiguration="BasicHttpBinding_ISpringContract"
????????????????????contract
="WcfContract.ISpringContract"?name="BasicHttpBinding_ISpringContract"?/>
????????
</client>
????
</system.serviceModel>
<startup><supportedRuntime?version="v4.0"?sku=".NETFramework,Version=v4.0"/></startup></configuration>

?

?

 四、在WCF客戶端增加配置文件Wcf.xml

  

Wcf.xml <?xml?version="1.0"?encoding="utf-8"??>
<objects?xmlns="http://www.springframework.net"
?????????xmlns:wcf
="http://www.springframework.net/wcf">

??
<wcf:channelFactory?id="SpringProxy"
????channelType
="WcfContract.ISpringContract,WcfContract"??????????????
????endpointConfigurationName
="BasicHttpBinding_ISpringContract">
????
<!--身份驗證-->
????
<wcf:property?name="Credentials.Windows.ClientCredential"?value="Domain\Login:Password"?/>
??
</wcf:channelFactory>
?
</objects>

?

?

  這樣,我可以無需“添加服務(wù)引用”,來實現(xiàn)動態(tài)調(diào)用WCF。注意的是我們需要引用WcfContract項目。

?

  五、WCF客戶端調(diào)用部分代碼

  

Program class?Program
????{
????????
static?void?Main(string[]?args)
????????{
????????????IApplicationContext?ctx?
=?ContextRegistry.GetContext();
????????????WcfContract.ISpringContract?proxy?
=?ctx.GetObject("SpringProxy")?as?WcfContract.ISpringContract;
????????????var?msg?
=?proxy.GetData(520);
????????????Console.Write(msg);

????????????Console.ReadLine();
????????}
????}

?

?

   運行效果:

  

?

?

  出處:http://www.cnblogs.com/GoodHelper/archive/2010/12/22/SpringNet131Wcf.html

  歡迎轉(zhuǎn)載,但需保留版權(quán)。

  代碼下載

轉(zhuǎn)載于:https://www.cnblogs.com/GoodHelper/archive/2010/12/22/SpringNet131Wcf.html

總結(jié)

以上是生活随笔為你收集整理的Spring.NET 1.3.1 新特性探索系列2——WCF命名空间解析器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。