2013-05-13 5 views
0

Google 서비스를 본사에서 실행중인 웹 서비스로 반환하는 고객 서버에서 유지 관리 작업을 실행하기 위해 Windows 서비스를 개발 중입니다.Windows 웹 서비스의 웹 API에 액세스

HTTP를 통해 직관적 인 웹 서비스를 구축하기위한 새롭고 간단한 대안으로 Web API를 사용했습니다. 그래서 우리의 HQ에있는 IIS 7에서 웹 API 웹 서비스를 호스팅 할 수 있는지 여부는 여러 원격 Windows 서비스에서 결과 집합을 반환하기 위해 액세스 할 수 있습니까?

답변

1

예 가능하며 asp.net에서 제공하는 specific guidance on how to do this이 있습니다.

원칙적으로, 클라이언트에서 다음 웹 API 프로젝트를 만들고 수행

HttpClient client = new HttpClient(); 
client.BaseAddress = new Uri("http://mywebapi.mycompany.com/"); 
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json")); 

var message = new MaintenanceResult { result = resultstatus, server = "servername" }; 
response = client.PostAsJsonAsync("api/maintenanceresults", message).Result; 
// now check for success, and response appropriately