encapsulate web service logic into other cs class
I used to have asp.net web application with web service (.asmx file) inside.
The web service actually holds the logic, for example:[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class SomeService : WebService
{
[WebMethod]
public bool DoSomething(long id)
{
Repository rep = new Repository();
Something fcs = rep.Get(m_User.CompanyId, id);
return fcs.IsOk;
}
}
Now I wish to put the logic code in its right project. So in MyServices project I created Some.cs file as follows:
public class Some
{
public bool DoSomething(long id)
{
Repository rep = new Repository();
Something fcs = rep.Get(m_User.CompanyId, id);
return fcs.IsOk;
}
}
Now I wish to recreate the .asmx file in the asp.net web application, but now I wish it use the methods in Some.cs.
I know I can do something like this:[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class SomeService : WebService
{
private Some m_Some;
public SomeService() {
m_Some=n开发者_JAVA技巧ew Some();
}
[WebMethod]
public bool DoSomething(long id)
{
return m_Some.DoSomething(id);
}
}
But I have more then 67 methods. So I would like to know if there is a way to "connect" the Some.cs methods with the SomeService service so that the service will use the methods from Some.cs?
No, there is no way to "connect" the Some.cs methods to the web service apart from manually wiring them.
The way you're doing it is fine.
精彩评论