1、可以作用一种IoC(或者说的DI)的容器实现程序的解耦。
{
//[WebMethod]
public string HelloWorld(string str)
{
return "Hello World: " + str;
}
[WebMethod]
public Person GetPerson()
{
return new Person {Age = 25, Name = "zhansan"};
}
[WebMethod]
public void SavePerson(Person person)
{
return;
}
}
2、通过Spring.Net提供WebService服务
{
string SayHello(string name);
int Add(int x, int y);
void SavePerson(Person person);
Person GetPerson(string name);
string GetPersonString();
}
{
#region IPerson 成员
public string SayHello(string name)
{
return "Hello word: " + name;
}
public int Add(int x, int y)
{
return x + y;
}
public void SavePerson(Person person)
{
return;
}
public Person GetPerson(string name)
{
return new Person {Age = 25, Name = "zhangsan"};
}
public string GetPersonString()
{
return JsonConvert.SerializeObject(new Person {Age = 25, Name = "zhangsan"});
}
#endregion
}
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler,Spring.Core"/>
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"></resource>
</context>
<objects xmlns="http://www.springframework.net" xmlns:aop="http://www.springframework.net/aop">
<object id="person" type="SpringWebServiceIoC.PersonService,SpringWebServiceIoC">
</object>
<object id ="personObj" type="SpringWebServiceIoCContract.Person,SpringWebServiceIoCContract"></object>
<object id="PersonService" type="Spring.Web.Services.WebServiceExporter,Spring.Web">
<property name="targetName" value="person"></property>
<property name="MemberAttributes">
<dictionary>
<entry key="Add">
<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="Description" value="计算量整数之和"></property>
<property name="MessageName" value="计算"></property>
</object>
</entry>
</dictionary>
</property>
</object>
</objects>
</spring>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpHandlers>
<add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web"/>
</httpHandlers>
<httpModules>
<add name="SpringModule" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>
</system.web>
</configuration>