Skip to Content
0
Mar 06 at 08:36 AM

SAP B1 API GateWay : 503,- Internal Server Error resulted from Runtime Exception

57 Views

Hi,

I am able to run "LoadAuthorizedCRList" api via postman

But when calling same endpoint in c#. It is giving me "503,- Internal Server Error resulted from Runtime Exception"

C# Code:

public string CreateReportLoginSession()
{
LoginServiceLayerModel _clsEntity_ServiceLayerLogin = new LoginServiceLayerModel();
_clsEntity_ServiceLayerLogin.CompanyDB = ConfigManager.GetSAPDatabase();
_clsEntity_ServiceLayerLogin.UserName = ConfigManager.GetSAPUserCode();
_clsEntity_ServiceLayerLogin.Password = ConfigManager.GetSAPPassword();
_clsEntity_ServiceLayerLogin.DBInstance = ConfigManager.GetDBInstance();
var login = JsonConvert.SerializeObject(_clsEntity_ServiceLayerLogin);
httpMethod = httpVerb.POST;
endPoint = ConfigManager.GetReportServiceLayerURL() + "login";
postJSON = login;
ServicePointManager.Expect100Continue = true;
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = (sender, x509Certificate, chain, sslPolicyErrors) => true;
string stringResponseValue = string.Empty;
try
{
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(endPoint);
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = httpMethod.ToString();
byte[] postBytes = Encoding.ASCII.GetBytes(postJSON);
request.ContentType = "application/json";
request.ContentLength = postBytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
HttpWebResponse response = null;
try
{
using (response = (HttpWebResponse)request.GetResponse())
{
if (response.StatusCode.Equals(HttpStatusCode.OK))
{
stringResponseValue = response.Headers.Get("Set-Cookie");
}
}
}
catch (WebException ex)
{
stringResponseValue = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
}
}
catch (Exception ex)
{
return ex.Message;
}
return stringResponseValue;
}
public void CallData()
{
string res = rc.CreateReportLoginSession();
var temp = JsonConvert.DeserializeObject<JArray>(main);
rc.endPoint = ConfigManager.GetReportServiceLayerURL() + "rs/v1/LoadAuthorizedCRList";
//rc.patchJSON = main;
rc.B1SESSION = res;
rc.httpMethod = httpVerb.GET;
string message = "";

bool result = rc.getRequest(out message);
}