【发布时间】:2011-08-20 02:03:59
【问题描述】:
我曾经有一个带有 Web 服务(.asmx 文件)的 asp.net Web 应用程序。
Web服务实际上持有逻辑,例如:
[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;
}
}
现在我希望将逻辑代码放入正确的项目中。所以在 MyServices 项目中我创建了 Some.cs 文件如下:
public class Some
{
public bool DoSomething(long id)
{
Repository rep = new Repository();
Something fcs = rep.Get(m_User.CompanyId, id);
return fcs.IsOk;
}
}
现在我希望在 asp.net Web 应用程序中重新创建 .asmx 文件,但现在我希望它使用 Some.cs 中的方法。
我知道我可以这样做:
[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=new Some();
}
[WebMethod]
public bool DoSomething(long id)
{
return m_Some.DoSomething(id);
}
}
但我有超过 67 种方法。所以我想知道是否有办法将 Some.cs 方法与 SomeService 服务“连接”,以便服务使用 Some.cs 中的方法?
【问题讨论】:
标签: asp.net web-services design-patterns