-1
這個簡單的WebserviceHost適用於.NET3.5,但不適用於4.0 我從瀏覽器使用URL http:// mycomputer:8081/SVC/HelloWorldWebServiceHost返回405在.NET4.0中不允許使用GET
3.5版本返回「Hello World!@ <時間>」字符串,但4.0版本返回 - 405不允許。
有誰知道爲什麼?
我用.net4.0一個的Win7 SP1 64位機
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();
}
}
沒有被寫入到事件日誌上。
有趣的是,它適用於我也用於開發的windowsXP/.net4.0虛擬機.. – mortb 2013-04-25 15:07:25