Post

2 followers Follow
0
Avatar

Unable to connect to the remote server

Hi, 

In my local machine every is working fine, but the same went to live i am getting the error like "Unable to connect to the remote server".

 

public LoginResultResponse Login(string UserName, string Password, string BaseAddress, string ServerLocation)
{
try
{
this.credentials = new ClarizenCredentials(UserName, Password);
string requestJson = JsonConvert.SerializeObject(credentials);
string responseJson = string.Empty;
string Uri = BaseAddress + ClarizenSession.GetServerDefinition;
rmc.TraceError("ClzHITLogininDLL_3_" + ClarizenSession.BaseAddress.ToString() + "____" + ClarizenSession.GetServerDefinition + "_" + Encoding.UTF8.GetBytes(requestJson).Length + "___" + requestJson);
// string Uri = "https://api.clarizen.com/v2.0/services/authentication/getServerDefinition";
string result1 = CAllRemotingServer(Uri, requestJson);
rmc.TraceError("ClzHITLogininDLL_3_" + result1.ToString());

response = JsonConvert.DeserializeObject<AuthenticateResponse>(result1);

requestJson = string.Empty;
responseJson = string.Empty;

ClarizenCredentials login = new ClarizenCredentials(credentials.Username, credentials.Password);
requestJson = JsonConvert.SerializeObject(login);

if (!string.IsNullOrEmpty(response.ServerLocation.ToString()))
{
Uri =response.ServerLocation + ClarizenSession.Login;
string result2 = CAllRemotingServer(Uri, requestJson);

loginResponse = JsonConvert.DeserializeObject<LoginResponse>(result2);
// rmc.TraceError("ClzHITLogininDLL_3_" + responseJson.ToString());
}

if (!string.IsNullOrEmpty(loginResponse.SessionId))
{
LoginResultResponse ObjLR = new LoginResultResponse();
ObjLR.SessionId = loginResponse.SessionId;
ObjLR.serverLocation = response.ServerLocation;
return ObjLR;
}
else
{
return null;
}
}
catch (WebException Wex)
{
var streamReader = new StreamReader(Wex.Response.GetResponseStream());
string s = streamReader.ReadToEnd();
var response = JsonConvert.DeserializeObject<ErrorMessage>(s);
rmc.TraceError("CLzUpdateTrackStatusinDLL___" + response.Message);
return null;
}
}

 

private string CAllRemotingServer(string Uri, string json)
{
// string uri = "https://api2.clarizen.com/v2.0/services/authentication/getServerDefinition";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Uri);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json";
request.ContentLength = json.Length;
// request.Accept = "application/json";
try
{
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(json);
}
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string tmp = reader.ReadToEnd();
return tmp;
rmc.TraceError("inHttpWebRequestnewmethod__respos___" + tmp);
}
}
catch(WebException ex)
{
rmc.TraceError("inHttpWebRequestnewmethod__error___" + ex.Message);
}
}

catch (WebException wex)
{
rmc.TraceError("inHttpWebRequestnewmethod " + wex.Message);
var streamReader = new StreamReader(wex.Response.GetResponseStream());
string s = streamReader.ReadToEnd();
rmc.TraceError("inHttpWebRequestnewmethod " + s);
}
return "";
}

 

the Code is DLL (Class Library) 

Thank you.,,,

surya Answered

Please sign in to leave a comment.

1 comment

0
Avatar

Hi Surya,

Your code generally seems OK.

It wasn't clear at what point you got the error on the production environment (for getServerDefinition or Login?).

Anyway, if that works on your development environment then I'd expect the issue to be with your production environment (e.g. it's not connected to the Internet or Clarizen's API address is blocked).

Hope this helps,

Ophir

Ophir Kenig 0 votes
Comment actions Permalink