我正在关注如何在位于此处的 WCF 服务中添加授权的指南。
现在我的问题是当我创建服务并从中删除 .DoWork() 方法时,我收到一条错误消息:
“Testing.HelloService”没有实现接口成员“Testing.IHelloService.DoWork()
这显然是因为我删除了它,但是需要它吗?在指南中,它基本上说要从中删除 .DoWork() 方法,所以我猜写它的人错过了一些东西。
当我创建它的服务时,它会将 HelloService 和 IHelloService 文件添加到项目中。我需要对 IHelloService 添加更改吗?
这是 HelloService.svc.cs 中的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Web;
using System.ServiceModel.Activation;
namespace MLA_Test_Service
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "HelloService" in code, svc and config file together.
[AspNetCompatibilityRequirements(
RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class HelloService : IHelloService
{
public string HelloWorld()
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
return HttpContext.Current.User.Identity.Name;
else
return "Unauthenticated Person";
}
}
}
这是来自 IHelloService.cs 的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace MLA_Test_Service
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IHelloService" in both code and config file together.
[ServiceContract]
public interface IHelloService
{
[OperationContract]
void DoWork();
}
}