[ServiceContract]
public interface IService
{
[OperationContract]
[WebGet(UriTemplate="/data")]
string GetData();
}
public class Service : IService
{
#region IService Members
public string GetData()
{
return "Hello";
}
#endregion
}
public class Program
{
static void Main(string[] args)
{
WebHttpBinding binding = new WebHttpBinding();
WebServiceHost host = new WebServiceHost(typeof(Service), new Uri("http://localhost:9876/MyService"));
host.AddServiceEndpoint(typeof(IService), binding, "http://localhost:9876/MyService");
host.Open();
Console.Read();
}
}
위의 코드는 정상적으로 작동합니다. 나는 HEAD 요청에 대해 405 (Method not allowed)를 얻는다. 사용중인 어셈블리의 버전은 System.ServiceModel.Web, Version = 3.5.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35입니다.
실제로 내가 아는 바로는 그것을 허용하는 직접적인 방법이 없다는 것입니다. 그러나 다음과 같은 해결책을 시도해 볼 수는 있습니다.하지만 GET 및 HEAD가 필요한 각 방법에 대해이 작업을 수행해야합니다. 그리 우아한 해결책 ..
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(Method = "*", UriTemplate = "/data")]
string GetData();
}
공용 클래스 서비스 : IService { # 지역 IService 회원
public string GetData()
{
HttpRequestMessageProperty request =
System.ServiceModel.OperationContext.Current.IncomingMessageProperties["httpRequest"] as HttpRequestMessageProperty;
if (request != null)
{
if (request.Method != "GET" || request.Method != "HEAD")
{
//Return a 405 here.
}
}
return "Hello";
}
#endregion
}
당신이 HEAD 동사의 운영 계약을하시기 바랍니다 게시 할 수 있습니까? –
[OperationContract] [WebGet (UriTemplate = "MyUri")] Stream MyContract(); –
3 년 후 여전히 문제가 있습니까? 나는 이것에 대한 해결책이 필요하다. –