자체 호스팅 서비스를 사용하여 wcf endpoint uri에서 서비스 작업을 호출 할 수 있습니까?REST 스타일에서 서비스 작업을 호출하는 방법 WCF 끝점 uri?
클라이언트가 서비스의 끝점 URI를 입력 할 때 일부 기본 서비스 작업을 호출하려고합니다. 선언 SayWelcome 작업을 호출하지 않습니다
- http://localhost:4711/clerk/hello
- http://localhost:4711/clerk/hi
그러나 URI
- http://localhost:4711/clerk
:이 URI를 올바르게 선언 된 작업 (sayHello가, SayHi)를 호출 다음 샘플에서는
. 대신 '메타 데이터 게시 금지'페이지로 연결됩니다. mex를 활성화해도 도움이되지 않습니다.이 경우 mex 페이지는 엔드 포인트 uri에 표시됩니다.
private void StartSampleServiceHost()
{
ServiceHost serviceHost = new ServiceHost(typeof(Clerk), new Uri("http://localhost:4711/clerk/"));
ServiceEndpoint endpoint = serviceHost.AddServiceEndpoint(typeof(IClerk), new WebHttpBinding(), "");
endpoint.Behaviors.Add(new WebHttpBehavior());
serviceHost.Open();
}
[ServiceContract]
public interface IClerk
{
[OperationContract, WebGet(UriTemplate = "")]
Stream SayWelcome();
[OperationContract, WebGet(UriTemplate = "/hello/")]
Stream SayHello();
[OperationContract, WebGet(UriTemplate = "/hi/")]
Stream SayHi();
}
public class Clerk : IClerk
{
public Stream SayWelcome() { return Say("welcome"); }
public Stream SayHello() { return Say("hello"); }
public Stream SayHi() { return Say("hi"); }
private Stream Say(string what)
{
string page = @"<html><body>" + what + "</body></html>";
return new MemoryStream(Encoding.UTF8.GetBytes(page));
}
}
mex 처리를 비활성화하고 대신 선언 된 작업을 활성화하는 방법이 있습니까?
미리 감사드립니다. Dieter
예, 사용해 보았습니다. 같은 결과. 이는 uri 템플리트 문자열의 처음과 끝에 슬래시가 무시된다는 MS 문서와 일치합니다. 불행히도 도움이되지 않습니다. Darrel에게 제안 해 주셔서 감사합니다. –
달レル, 정말 고마워. WebServiceHost가 차이를 만듭니다. ServiceHost 대신 WebServiceHost를 사용하면 모든 것이 잘 작동합니다! 최고 감사원, 디터 –