我有一个现有的 Web 应用程序,其中 asp.net 客户端通过使用业务项目的 dll 来使用业务。商业项目的代码如下。
现在,我们需要将其设为 WCF Web 服务。我需要从现有的 BankAccountService 类创建一个服务接口(合同)。但是该类有一个重载的构造函数。此构造函数不能在服务接口中定义(因为 Web 服务不是面向对象的)。我可以在这里使用什么使其作为 Web 服务运行的最佳解决方案是什么?
我们是否需要创建任何外观而不是将 BankAccountService 作为服务实现?
注意:我了解在实现服务后提取接口不是一个好习惯。但是对于这种特殊情况,我们需要这样做。
注意:这是一个非常简单的应用程序,这是应用程序中唯一需要的功能。该网站将是唯一使用该服务的客户。
参考:
代码
namespace ApplicationServiceForBank
{
public class BankAccountService
{
RepositoryLayer.IRepository<RepositoryLayer.BankAccount> accountRepository;
ApplicationServiceForBank.IBankAccountFactory bankFactory;
public BankAccountService(RepositoryLayer.IRepository<RepositoryLayer.BankAccount> repo, IBankAccountFactory bankFact)
{
accountRepository = repo;
bankFactory = bankFact;
}
public void FreezeAllAccountsForUser(int userId)
{
IEnumerable<RepositoryLayer.BankAccount> accountsForUser = accountRepository.FindAll(p => p.BankUser.UserID == userId);
foreach (RepositoryLayer.BankAccount repositroyAccount in accountsForUser)
{
DomainObjectsForBank.IBankAccount acc = null;
acc = bankFactory.CreateAccount(repositroyAccount);
if (acc != null)
{
acc.BankAccountID = repositroyAccount.BankAccountID;
acc.accountRepository = this.accountRepository;
acc.FreezeAccount();
}
}
}
}