[英]WCF Service- Does not implement interface member
現在我的問題是當我創建服務並從其中刪除.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();
}
}
您的實現需要匹配您的界面。 如果您不想實現DoWork方法,則需要從實現和接口開始。
實際上,您可能應該只將DoWork替換為您實際要在服務上調用的方法的名稱,並改為實現該方法。 它應作為如何在WCF服務上啟動操作的示例。
它是簡單的C#,您要繼承一個接口,必須在類中實現該接口的所有已聲明方法。
DoWork()
存在於您的Interface中,因此可以在HelloService
類中實現它。
而且,只有那些方法對WCF-Service客戶端可見,這些方法將在OperationContract
即接口中聲明,並標記為[OperationContract]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.