ここにある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();
}
}