【问题标题】:How to create new method into exiting WCF services?如何在现有 WCF 服务中创建新方法?
【发布时间】:2016-03-17 10:42:17
【问题描述】:

我有一个现有的 WCF 服务项目。我想根据我的新要求创建新方法。如何在我的 WCF 服务中创建新方法?我也想通过存储过程访问数据库。

【问题讨论】:

  • 是 OperationContract 方法吗?只需添加新方法……这并不是什么难事。有代码吗?

标签: c# wcf model-view-controller


【解决方案1】:

您可以将新的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...
        }
  }

也许你可以展示一些你的代码...

【讨论】:

  • 谢谢,我很感激。
猜你喜欢
  • 2020-04-27
  • 2015-10-21
  • 2016-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多