如何在现有WCF服务中创建新方法



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

您可以在ServiceContract中添加一个新的OperationContract,如:

[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...
        }
  }

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

相关内容

最新更新