【问题标题】:encapsulate web service logic into other cs class将 Web 服务逻辑封装到其他 cs 类中
【发布时间】: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


    【解决方案1】:

    不,除了手动连接它们之外,没有办法将 Some.cs 方法“连接”到 Web 服务。
    你这样做的方式很好。

    【讨论】:

      猜你喜欢
      • 2011-10-17
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      • 2013-04-15
      • 1970-01-01
      • 1970-01-01
      • 2011-02-17
      相关资源
      最近更新 更多