I am new to REST webservices. There is an existing REST service that I need to consume in a C# console application. I am getting the XML response in the following line.
readStream.ReadLine();
How can we make use of the REST response in the client?
Utility
public void SearchContactDetailsAsync(Models.AddressBookRequest addressBookDataRequest)
{
UriBuilder builder = new UriBuilder(url);
restClient.DoPost(builder.Uri, Serializer.SerializeXml(addressBookDataRequest.contactsSearchCriteria), SearchContactSuccess, SearchContactFailed, addressBookDataRequest.HeaderParams);
}
private void SearchContactSuccess(HttpWebResponse response)
{
//Call base service method - to inspect the response and publish an event
HandleServiceSearchSuccess<ContactDetailsPreview[]>(SearchContactDetailsCompleted, "contactDetailsPreviews", response);
Stream receiveStream = response.GetResponseStream();
Encoding encode = System.Text.Encoding.UTF8;
StreamReader readStream = new StreamReader(receiveStream, encode);
readStream.ReadLine();
}
Console App
public void MyMethod()
{
autoRestEvent = new AutoResetEvent(false);
services = new communicationSvcs();
services.SearchContactDetailsCompleted += new EventHandler<RestClientUtility.EventArg.ServiceResponseEventArgs<RestClientUtility.Models.ContactDetailsPreview[]>>(services_SearchContactDetailsCompleted);
//Call the operation
AddressBookRequest req = new AddressBookRequest
{
contactsSearchCriteria = new ContactsSearchCriteria
{
searchUserID = "ss23ed"
},
HeaderParams = new RestClientUtility.Requests.HttpHeaderParms
{
UserId = "ss23ed",
UserPrincipalName = " ss23ed@hotmail.com",
ContentType = "application/xml"
}
};
services.SearchContactDetailsAsync(req);
autoRestEvent.WaitOne();
}
References