2012-03-30 33 views
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\"}")); 

服務代碼 如果我刪除突出顯示代碼,然後它工作正常。我不知道我在這裏錯過了什麼? enter image description here enter image description here獲取在WCF服務空對象時,我增加了效應初探格式和車身風格

回答

1

您必須在上傳的JSON中包含參數的名稱。所以:

{"param1": {"FirstName":"John","LastName":"Doe"}} 

它沒有解釋爲什麼雖然它工作沒有突出顯示的代碼......

這是否解決問題了嗎?

相關問題