2014-02-17 63 views
0

我試着在腳本#腳本#調用REST服務

Uri uri = new Uri(string.Format(string.Concat("http://localhost:49175/GetProjects"))); 
WebRequest request = WebRequest.Create(uri); 
request.Method = WebRequestMethods.Http.Get; 
request.ContentType = "application/json"; 
using (WebResponse response = request.GetResponse()) { 
    using (var reader = new System.IO.StreamReader(response.GetResponseStream())) { 
    string tmp = reader.ReadToEnd(); 
    return JsonConvert.DeserializeObject<List<string>>(tmp); 
    } 
} 

使用此代碼,但我有這樣的錯誤:

Error 3 The assembly 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.dll' is not a valid script assembly.

是否在使用System.NetSystem.IO.StreamReaderNewtonsoft.Json方式腳本#?如果不可能,我該如何更改代碼?

+0

您不能引用的.NET程序集的腳本#解決了這個問題。另外,S#只與C#2.0規範兼容。 – theoutlander

回答

1

我這樣

string tfsIntegration = string.Format(string.Concat("http://localhost:49175")); 

System.Net.XmlHttpRequest getProjectRequest = new System.Net.XmlHttpRequest(); 

getProjectRequest.Open("GET", tfsIntegration + "/GetProjects", false); 
getProjectRequest.SetRequestHeader("Accept", "application/json"); 
getProjectRequest.SetRequestHeader("Content-Type", "application/json; charset=utf-8"); 
getProjectRequest.SetRequestHeader("X-HTTP-Method", "MERGE");    
getProjectRequest.Send(null);