Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF服务-未实现接口成员_C#_Asp.net_.net_Asp.net Mvc_Wcf - Fatal编程技术网

C# WCF服务-未实现接口成员

C# WCF服务-未实现接口成员,c#,asp.net,.net,asp.net-mvc,wcf,C#,Asp.net,.net,Asp.net Mvc,Wcf,我正在遵循一个关于如何在WCF服务中添加授权的指南 现在我的问题是,当我创建服务并从中删除.DoWork()方法时,我会得到一个错误,上面说: 'Testing.HelloService'未实现接口成员'Testing.IHelloService.DoWork() 这显然是因为我删除了它,但它是必要的吗?在指南中,它基本上说要从中删除.DoWork()方法,所以我认为编写它的人遗漏了一些东西 当我创建it服务时,它会将HelloService和IHelloService文件添加到项目中。我是否需

我正在遵循一个关于如何在WCF服务中添加授权的指南

现在我的问题是,当我创建服务并从中删除.DoWork()方法时,我会得到一个错误,上面说:

'Testing.HelloService'未实现接口成员'Testing.IHelloService.DoWork()

这显然是因为我删除了它,但它是必要的吗?在指南中,它基本上说要从中删除.DoWork()方法,所以我认为编写它的人遗漏了一些东西

当我创建it服务时,它会将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();
    }
}

您的实现需要与您的接口相匹配。如果不想实现DoWork方法,则需要从实现和接口开始


事实上,您可能应该将DoWork替换为实际要在服务上调用的方法的名称,并实现该方法。它应该作为如何在WCF服务上启动操作的示例。

您的实现需要与您的接口相匹配。如果不想实现DoWork方法,则需要从实现和接口开始

事实上,您可能应该将DoWork替换为实际要在服务上调用的方法的名称,并实现该方法。它应该作为如何在WCF服务上启动操作的示例。

它的简单C#,如果您继承了一个接口,您必须在类中实现它的所有声明方法

DoWork()
存在于接口中,因此在
HelloService
类中实现它

此外,只有那些方法对您的WCF服务客户端可见,这些方法将在
OperationContract
即接口中声明,并标记为
[OperationContract]
它的简单C;,如果您继承了一个接口,则必须在类中实现该接口的所有声明方法

DoWork()
存在于接口中,因此在
HelloService
类中实现它


此外,您的WCF服务客户端只能看到这些方法,这些方法将在
操作合同
即界面中声明,并标记为
[OperationContract]

您需要从界面中删除
DoWork
方法,否则,任何未实现
DoWork
的实现类都将抛出该错误到接口。您需要从接口中删除
DoWork
方法,否则任何未实现
DoWork
的实现类将抛出该错误。您还需要添加
[OperationContract]字符串HelloWorld()到接口。