【发布时间】:2016-03-17 10:42:17
【问题描述】:
我有一个现有的 WCF 服务项目。我想根据我的新要求创建新方法。如何在我的 WCF 服务中创建新方法?我也想通过存储过程访问数据库。
【问题讨论】:
-
是 OperationContract 方法吗?只需添加新方法……这并不是什么难事。有代码吗?
标签: c# wcf model-view-controller
我有一个现有的 WCF 服务项目。我想根据我的新要求创建新方法。如何在我的 WCF 服务中创建新方法?我也想通过存储过程访问数据库。
【问题讨论】:
标签: c# wcf model-view-controller
您可以将新的OperationContract 添加到您的ServiceContract 中,例如:
[ServiceContract()]
public interface IMyService
{
[OperationContract]
bool DoSomething(string param);
}
然后在ServiceBehavior中实现方法:
[ServiceBehavior()]
public class MyService
: IMyService
{
public bool DoSomething(string param)
{
//Do Something....
}
}
或在 MVC 中为您的 ApiController 添加一个新方法,例如:
public class MyController : ApiController
{
[Route("api/DoSomething/")]
[HttpGet]
public bool DoSomething(string param)
{
//Do Something...
}
}
也许你可以展示一些你的代码...
【讨论】: