1
string baseAddress = "http://" + Environment.MachineName + ":8000/RestServiceImpl";
ServiceHost host = new ServiceHost(typeof(RestServiceImpl), new Uri(baseAddress));
//host.AddServiceEndpoint(typeof(IRestServiceImpl), new WebHttpBinding(), "").Behaviors.Add(new GainSoft.TaskManager.Service.RestServiceImpl.MyWebHttpBehavior());
host.AddServiceEndpoint(typeof(IRestServiceImpl), new WebHttpBinding(), "").Behaviors.Add(new WebHttpBehavior());
ServiceDebugBehavior sdb = host.Description.Behaviors.Find<ServiceDebugBehavior>();
sdb.HttpHelpPageEnabled = false;
host.Open();
Console.WriteLine("Host opened");
WebClient client = new WebClient();
// Console.WriteLine(client.DownloadString(baseAddress + "/InsertData?param1=John,Doe"));
try
{
client = new WebClient();
client.Headers[HttpRequestHeader.ContentType] = "application/json";
Console.WriteLine(client.UploadString(baseAddress + "/InsertData", "{\"FirstName\":\"John\",\"LastName\":\"Doe\"}"));
服務代碼 如果我刪除突出顯示代碼,然後它工作正常。我不知道我在這裏錯過了什麼? 獲取在WCF服務空對象時,我增加了效應初探格式和車身風格