이 간단한 WebserviceHost는 .NET3.5에 대해 4.0을 컴파일 할 때 작동합니다. URL http : // mycomputer : 8081/SVC/HelloWorldWebServiceHost가 .NET4.0의 GET에서 허용되지 않음
3.5 버전은 "Hello World! @ <time>"문자열을 반환하지만 4.0 버전은 - 405 Not Allowed를 반환합니다.
이유를 아는 사람이 있습니까?
나는
using System;
using System.Web.Services;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Collections.Generic;
using System.Runtime.Serialization;
[ServiceContract]
public interface IMyService
{
[OperationContract]
[WebGet(UriTemplate = "HelloWorld")]
string HellWorld();
}
public class MyService : IMyService
{
public string HellWorld()
{
return "Hello World! @ " + DateTime.Now.ToString("s");
}
}
public class MyClass
{
public static void Main()
{
string myComputer = "myComputer";
string mySvcUri = "http://" + myComputer + ":8081/SVC";
Uri[] baseAddresses = new Uri[] { new Uri(mySvcUri) };
WebServiceHost hostVisits = new WebServiceHost(typeof(MyService), baseAddresses);
BasicHttpBinding binding = new BasicHttpBinding();
hostVisits.AddServiceEndpoint(typeof(IMyService), binding, "MyService");
hostVisits.Open();
Console.WriteLine("Service host started, press any key to exit");
Console.ReadKey();
}
}
아무 것도 이벤트 로그에 기록되지 않는 Win7에 SP1 64 비트 시스템에서 .net4.0 사용하고 있습니다.
흥미롭게도 나는 개발 용으로 사용하는 windowsXP/.net4.0이있는 가상 컴퓨터에서 작동합니다. – mortb