ServiceStackを使用して単純なWebサービスを作成しようとしています。サーバー(サービス)側では、最初にユーザー「administrator」を作成し、それに「Admin」ロールを割り当てました。ServiceStackの組み込みの資格情報認証を使用していますが、適切に認証されます。ただし、[Authenticate]属性で装飾されたWebサービスを後で呼び出すと、次のエラーが返されます。
OAuthプロバイダー「基本」の構成は追加されませんでした
参考:データベースはRavenDbです-ServiceStack.Authentication.RavenDbを使用しています。また、App_Start.AppHost.Configure()にMemoryCacheClientを登録しました。App_Start.AppHostクラスのすべてのコードを表示する必要がある場合はお知らせください。
サーバーコード(抜粋):
namespace MyTest
{
[Route("/hello")]
[Route("/hello/{Name}")]
[Authenticate]
public class Hello
{
public string Name { get; set; }
}
public class HelloResponse
{
public string Result { get; set; }
}
public class HelloService : Service
{
public IUserAuthRepository UserAuthRepo { get; set; }
public object Any(Hello request)
{
return new HelloResponse { Result = "Hello, " + request.Name };
}
}
}
クライアント側:
var client = new JsonServiceClient("http://127.0.0.1:65385/auth/credentials?format=json");
var auth = new Auth { UserName = "administrator", Password = "12345" };
var authResponse = client.Post(auth);
if (authResponse.ResponseStatus.ErrorCode == null)
{
client = new JsonServiceClient("http://127.0.0.1:65385/hello");
client.UserName = "administrator";
client.Password = "12345";
// When sending the request - it returns "Not Found"
var helloResponse = client.Send(new Hello { Name = "John" });
}
編集:私のサービスのweb.configは、HelloWorld チュートリアルの
セクション2aに書かれているものとまったく同じように見えます
AppHostの構成は次のとおりです。
public override void Configure(Funq.Container container)
{
container.Register(new MemoryCacheClient { FlushOnDispose = false });
container.Register(new EmbeddableDocumentStore { DataDirectory = "Data" }.Initialize());
ConfigureAuth(container);
}
private void ConfigureAuth(Funq.Container container)
{
var appSettings = new AppSettings();
Plugins.Add(new AuthFeature(() => new CustomUserSession(),
new IAuthProvider[] {
new CredentialsAuthProvider(appSettings)}));
Plugins.Add(new RegistrationFeature());
container.Register(
new RavenUserAuthRepository(c.Resolve()));
}