2013-04-25 1 views
-1

이 간단한 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 사용하고 있습니다.

+0

흥미롭게도 나는 개발 용으로 사용하는 windowsXP/.net4.0이있는 가상 컴퓨터에서 작동합니다. – mortb

답변

1

그냥이 두 줄을 제거하십시오. 효과가있을 것입니다.

BasicHttpBinding binding = new BasicHttpBinding(); 
hostVisits.AddServiceEndpoint(typeof(IMyService), binding, "MyService"); 
+0

있습니다. 왜 그런지 알아? 위의 코드는 다른 사람이 작성한 프로젝트에서 추출한 것입니다. 따라서이 코드가 작동하지 않는 이유를 정확히 알지 못합니다 ... – mortb

관련 문제