Spring. Net for distributedProgramThe support is obvious to all. In versions earlier than 1.3.1, remoting and WebService are well supported and have their corresponding parser. However, it does not provide perfect support for WCF. However, Version 1.3.1 includes the namespace parser function of WCF. After importing the xmlns: WCF = "http://www.springframework.net/wcf" namespace, you can use the configuration provided by the parser.
1. Create a WCF contract assembly:Wcfcontract.
Create an InterfaceIspringcontract
Namespace Wcfcontract
{
[Servicecontract]
Public Interface Ispringcontract
{
[Operationcontract]
String Getdata ( Int Value );
}
}
2. Create a server project wcfserver for WCF.
Create the springservice. SVC file.SpringserviceClass inheritanceIspringcontract
Springservice
Namespace Wcfserver
{
Public Class Springservice: ispringcontract
{
Public String Getdata ( Int Value)
{
Return String . Format ( " You entered: {0} " , Value );
}
}
}
3. Create a wcfclient for the WCF client project
Configure 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" Maxcompute edmessagesize = "65536"
Messageencoding = "Text" Textencoding = "UTF-8" Transfermode = "Buffered"
Usedefawebwebproxy = "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 >
4. Add the configuration file WCF. XML to the WCF client.
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" >
<! -- Authentication -->
< WCF: Property Name = "Credentials. Windows. clientcredential" Value = "Domain \ login: Password" />
</ WCF: channelfactory >
</ Objects >
In this way, I can dynamically call WCF without having to "add service reference. Note that we need to referenceWcfcontractProject.
5. Call the WCF ClientCode
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 ();
}
}
Running effect:
Source: http://www.cnblogs.com/GoodHelper/archive/2010/12/22/SpringNet131Wcf.html
You are welcome to reprint it, but you must retain the copyright.
Code download