-1

この単純な WebserviceHost は、.NET3.5 用にコンパイルすると機能しますが、4.0 では機能しません。ブラウザーから URL http:// mycomputer:8081/SVC/HelloWorld でアクセスします。

3.5 バージョンは「Hello World! @ <time>」文字列を返しますが、4.0 バージョンは - 405 Not Allowed を返します。

誰かが理由を知っていますか?

Win7 SP1 64 ビット マシンで .net4.0 を使用しています

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();
    }
}

イベントログには何も書き込まれません。

4

1 に答える 1