Hi,
I have a serviceContract Class in which i have a function which returns a string "HelloWorld".
I've made a service which refers to this class and the service operation is that of the method which returns the srting. And added this service to the service group and set its AutoDeploy to YES.
Now, on the client side, I've given the URI and other authorization details in the code which are working fine but it gives an exception at this part of the code where I need to get the response string from the method.
Here is the code snippet:
using AuthenticationUtility;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
namespace OAuthXppConsoleApplication
{
class Program
{
public static string GetUserSessionOperationPath = ClientConfiguration.Default.UriString + "api/services/EgxCompanyInfoServiceGroup/EgxCompanyInfoService/getHello";
static void Main(string[] args)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(ClientConfiguration.Default.UriString);
client.DefaultRequestHeaders.Add(OAuthHelper.OAuthHeader, OAuthHelper.GetAuthenticationHeader());
using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "api/services/EgxCompanyInfoServiceGroup/EgxCompanyInfoService/getHello"))
{
request.Content = new StringContent(String.Empty, Encoding.UTF8, "application/json");
var httpResponse = client.SendAsync(request).Result;
httpResponse.EnsureSuccessStatusCode();
var result = httpResponse.Content.ReadAsStringAsync().Result;
Console.WriteLine(result.ToString());
}
Console.ReadLine();
}
}
}
I've tried with both methods, post and get but they return different exceptions and not the result.
What is wrong in the code? Can anyone explain?
*This post is locked for comments
I have the same question (0)