ServerReport Render timeout - c#

I'm implementing serverReport in a CRM workflow.(not online version)
I set the workflow non-sandbox and I'm trying to implement a version of ServerReport i'm using in a C# Webservice.
This is the code: (the last line is the one throwing the exception)
sr.ReportServerUrl = new Uri(reportServerBaseURL);
sr.ReportPath = reportDir + reportName;
// Credential to connect with CRM
IReportServerCredentials irsc = new CustomReportCredentials(username, password, "");
sr.ReportServerCredentials = irsc;
if (paramList != null && paramList.Count > 0)
{
bool isTimeout = true;
for (int i = 0; i < 6; i++)
{
try
{
sr.Timeout = 5000;
sr.Refresh();
sr.SetParameters(paramList);
isTimeout = false;
break;
}
catch (Exception ex)
{
}
}
if (isTimeout)
{
string message = "Report timeout";
throw new Exception(message);
}
}
sr.Timeout = 5000;
sr.Refresh();
string renderingString = null;
switch (renderingMethod)
{
case RSRenderingMethods.PDF:
renderingString = "PDF";
break;
case RSRenderingMethods.EXCEL:
renderingString = "EXCEL";
break;
case RSRenderingMethods.PNG:
case RSRenderingMethods.JPEG:
case RSRenderingMethods.GIF:
case RSRenderingMethods.TIFF:
renderingString = "IMAGE";
break;
}
//I'm reaching this point without problems, the format I'm using is PDF
byte[] bytes = bytes = sr.Render(renderingString, null); //this line is throwing the exception
With the WebService I had no problems for the report rendering, and I don't know why this time I'm having them.
The report is about 30-40 rows, so it's not big at all. Might the problem be in something I'm doing?

Related

Insert Data SAP B1 with C#

I'm trying to input purchase order data with the DI API in C #. after I run the script, the connection is successful and the input data is successful but when I check SAP the input data is not there.
this is the script I used:
try
{
SAPbobsCOM.Documents PO = null;
PO = ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders);
PO.CardCode = "VT0970";
PO.CardName = "FELICOM";
PO.Series = int.Parse("16N");
PO.DocNum = 211000002;
PO.DocDate = DateTime.Parse("15.10.19");
PO.DocDueDate = DateTime.Parse("18.10.19");
PO.TaxDate = DateTime.Parse("15.10.19");
PO.Lines.ItemCode = "TH-NONSTOK";
PO.Lines.ItemDescription = "Mouse Rexus G-6";
PO.Lines.Quantity = 2;
PO.Lines.Price = 150000;
PO.DiscountPercent = 0;
PO.Lines.VatGroup = "IPPN0";
PO.Lines.AccountCode = "6020-1500";
PO.Lines.Add();
int res = PO.Add();
if (res == 0)
{
MessageBox.Show("Add Purchase Order successfull");
}
else
{
MessageBox.Show(ocompany.GetLastErrorDescription()); //#scope_identity
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Is there something wrong with my script?
Please help.
after "Add Purchase Order successfull" should be commit work
if (ocompan.InTransaction)
ocompan.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
else
throw new Exception("ERROR: Transaction closed before EndTransaction!!!");

Our SNTP Server is not responding for my requests

I have written a SNTP Client code to retrieve time information as below. In this, the code stops at line
_sntpMessageRequest.SNTPData = _udpClient.Receive(ref _ipEndpoint);
as SNTP Server is not responding.
public bool QueryTimeSynchronizationServer()
{
UdpClient _udpClient = null;
IPEndPoint _ipEndpoint = null;
string _ipString = null;
IPAddress _ipAddress = null;
int _portNumber = 123;
try
{
//Valid Ip Address
_ipString = "ip address";
IPAddress.TryParse(_ipString, out _ipAddress);
_ipEndpoint = new IPEndPoint(_ipAddress, _portNumber);
//SNTPMessageRequest-> a object holds the Byte array for SNTP request and do other supporting functions
SNTPMessageRequest _sntpMessageRequest = FrameSNTPMessageRequest();
using (_udpClient = new UdpClient(123))
{
_udpClient.Client.SendTimeout = 5000;
_udpClient.Client.ReceiveTimeout = 5000;
_udpClient.Connect(_ipEndpoint);
_udpClient.Send(_sntpMessageRequest.SNTPData, _sntpMessageRequest.SNTPData.Length);
//Code stops at below line as SNTP Server is not responding.
_sntpMessageRequest.SNTPData = _udpClient.Receive(ref _ipEndpoint);
_sntpMessageRequest.ReceptionTimestamp = DateTime.Now;
string _serverTime = _sntpMessageRequest.TransmitTimeStamp.ToString();
}
}
catch (Exception ex)
{
}
return true;
}
private SNTPMessageRequest FrameSNTPMessageRequest()
{
SNTPMessageRequest _sntpMessageRequest = new SNTPMessageRequest();
_sntpMessageRequest.VersionNumber = VersionNumber.Version3;
_sntpMessageRequest.Mode = Mode.Client;
for (int i = 1; i < 48; i++)
{
_sntpMessageRequest.SNTPData[i] = 0;
}
_sntpMessageRequest.TransmitTimeStamp = DateTime.Now.ToLocalTime();
return _sntpMessageRequest;
}
Kindly help me with where i am doing mistake.

Connect to a Webservice - convert C# to PHP code

I have a sample code I got from a documentation provided by a merchant. I think the code is in C#. I need to write a code for PHP but I don't have any idea about C# so I'm having a problem with this. I've tried to write a PHP code for this but it doesn't seem right.
By the way, this is a webservice kind of setup and it uses WCF to expose various endpoints. Here's the endpoint they've provided to me: http://services.scorpion.biz/Public/Leads/ExternalLead.svc
Here's the C# code:
public bool SubmitLead(string contactName, string contactNumber) {
bool outcome = false;
string message = string.Empty;
if (contactNumber.Length <= 9) {
message = "Telephone number is too short";
outcome = false;
} else if (contactNumber.Length > 11) {
message = "Telephone number is too long";
outcome = false;
} else if (contactNumber.Length == 10 && contactNumber[0] != '0') {
message = "Telephone must start with a ZERO";
outcome = false;
} else if (contactNumber.Length == 11 && contactNumber.Substring(0, 2) != "27") {
message = "Telephone must start with a 27";
outcome = false;
} else {
WSExternalLead.LeadRequestMessage request = new
WSExternalLead.LeadRequestMessage();
request.Message = “Your Keyword” + ". Contact Name: " + contactName + ".
Contact Number: " + contactNumber;
request.TelephoneNumber = contactNumber;
request.Network = “IMU”;
request.ReceivedTime = DateTime.Now;
using (WSExternalLead.ExternalLeadClient client = new WSExternalLead.ExternalLeadClient()) {
try {
WSExternalLead.LeadResponseMessage response = null;
response = client.GenerateLead(request);
if (response.Result != true) {
message = "We were unable to process your request at this
time. Error: " + response.ErrorMessage;
outcome = false;
} else {
message = "Thank you for your interest in Scorpion Legal
Protection. We will get back to you shortly.";
outcome = true;
}
} catch (FaultException fx) {
message = "We were unable to process your request at this time.
Fault: " + fx.Message;
outcome = false;
} catch (Exception ex) {
message = "We were unable to process your request at this time.
Exception: " + ex.Message;
outcome = false;
}
}
}
HttpContext.Current.Session["OUTCOME"] = outcome;
HttpContext.Current.Session["MESSAGE"] = message;
return outcome;
}
Here's the PHP code that I've written:
// Read values to variables
$username = $_GET['un'];
$usersurname = $_GET['ul'];
$phonesubmit= $_GET['up'];
$useremail = $_GET['ue'];
$aff_id = $_GET['aff'];
$unique_id = $_GET['uid'];
$rdate = date('m/d/Y G:i:s');
$rdate = date("c", strtotime($rdate));
$wsdlFile = "http://services.scorpion.biz/Public/Leads/ExternalLead.svc?WSDL";
$client = new SoapClient($wsdlFile);
$variables->TelephoneNumber = $phonesubmit;
$variables->Message = "IMU. Name: $username $usersurname. Contact Number: $phonesubmit";
$variables->Network = "IMU";
$variables->ReceivedTime = $rdate;
$result = $client->GenerateLead($variables);
$returnMessage = $result->Result;
$returnMessage = trim($returnMessage);
if ($returnMessage == ""){
$returnMessage = $result->ErrorMessage;
}
Any idea on how to solve this would be greatly appreciated. Thanks.

Parallel.Foreach do not finish stream

For load testing purposes I need to simulate multiple users trying to login to a system at the same time. I have code written by another developer that can send a login request to the system. With an ok login it will also return other information in xml.
I've tried using Parallel.ForEach, but dont have any real experience with parallel programming:
Parallel.ForEach(clientList, client =>
{
RunTest(client);
});
public void RunTest(object data)
{
if (!(data is IGprsClient))
{
return;
}
_noRunningTests += 1;
IGprsClient gprsClient = data as IGprsClient;
DateTime startTime = DateTime.Now;
Log(gprsClient.Id, "Test started.");
bool result = gprsClient.StartTest(20000);
DateTime endTime = DateTime.Now;
TimeSpan diff = endTime - startTime;
if (result == false)
{
Log(gprsClient.Id, "Test failed.");
}
Log(gprsClient.Id, "Test took {0}ms. ", (int)diff.TotalMilliseconds);
_noRunningTests -= 1;
}
override public bool StartTest(int timeout)
{
_testStarted = true;
try
{
LogDebug("Trying to connect.");
_client = new TcpClient(ipAddress, port);
LogDebug("Connected.");
bool result = false;
//Todo: insert testcase into client
switch (TestCaseName)
{
case "LoginTEST":
var testCase = new LoginTEST(this);
result = testCase.Execute(user, pwd, phoneNum);
break;
default:
Log("Unknown test case: " + TestCaseName);
break;
}
_client.Close();
return result;
}
catch (Exception ex)
{
if (_client != null)
_client.Close();
Log(ex.Message);
return false;
}
}
Which in turn will send the request and read the response.
public bool Execute(string user, string pwd, string phoneNum)
{
SendDataListRequest(userId);
string requiredDataResponse = Client.ReadMsg();
return true;
}
Run test will send a request and reads the message like so:
public string ReadMsg()
{
int msgLength = -1;
var stream = _client.GetStream();
while (_testStarted)
{
int b = stream.ReadByte();
if (b == -1)
{
return "";
}
else if (b == 0x02 || msgLength == -1)
{
while (b != 0x02 && _testStarted)
{
b = stream.ReadByte(); // Finds the start token
if (b == -1)
{
return "";
}
}
msgLength = 0; // Starts collecting data
}
else if (b == 0x03)
{
byte[] encryptedMsg = Convert.FromBase64String(
Encoding.UTF8.GetString(byteBuffer, 0, msgLength));
byte[] decryptedMsg = SttCipher.DecryptMessage(encryptedMsg);
MemoryStream ms = new MemoryStream(decryptedMsg);
GZipStream gZipStream = new GZipStream(ms, CompressionMode.Decompress, true);
var bufLen = ReadAllBytesFromStream(gZipStream, decompressedBuffer);
gZipStream.Close();
string completeMsg = Encoding.UTF8.GetString(decompressedBuffer, 0, bufLen);
if (completeMsg.Length < 500)
LogDebug("Received XML-data:\n{0}", completeMsg);
else
LogDebug("Received XML-data: {0} bytes\n{1}...", completeMsg.Length, completeMsg.Substring(0, 500));
return completeMsg;
}
else
{
if (byteBuffer.Length <= msgLength)
{
throw new Exception("XML message too long!");
}
byteBuffer[msgLength] = (byte)b;
msgLength++;
}
}
return "";
}
Running one client is fine and will wait for the response. The issue is with several clients, the responses gets cut off. Leaving me with unclosed xml in the response.But I cant't figure out why. Does anyone have a reasonable explanation and/or a solution or a better way of doing it?

C2DM-Sharp Error:Invalid registration

i am using c2dm-sharp for sending push notification to android device.
i was working fine but from some time its showing some error: message failed invalid registration
when i debug the code i found that in C2dmMessageTransport.cs file of C2dmSharp.Server project in below method its giving error at var webResp = webReq.GetResponse() as HttpWebResponse;
error is - the underlying connection was closed an unexpected error occurred on a send
static C2dmMessageTransportResponse send(C2dmMessage msg, string googleLoginAuthorizationToken, string senderID, string applicationID)
{
C2dmMessageTransportResponse result = new C2dmMessageTransportResponse();
result.Message = msg;
var postData = msg.GetPostData();
var webReq = (HttpWebRequest)WebRequest.Create(C2DM_SEND_URL);
// webReq.ContentLength = postData.Length;
webReq.Method = "POST";
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.UserAgent = "C2DM-Sharp (version: 1.0)";
webReq.Headers.Add("Authorization: GoogleLogin auth=" + googleLoginAuthorizationToken);
using (var webReqStream = new StreamWriter(webReq.GetRequestStream(), Encoding.ASCII))
{
var data = msg.GetPostData();
webReqStream.Write(data);
webReqStream.Close();
}
try
{
var webResp = webReq.GetResponse() as HttpWebResponse;
if (webResp != null)
{
result.ResponseStatus = MessageTransportResponseStatus.Ok;
//Check for an updated auth token and store it here if necessary
var updateClientAuth = webResp.GetResponseHeader("Update-Client-Auth");
if (!string.IsNullOrEmpty(updateClientAuth) && C2dmMessageTransport.UpdateGoogleClientAuthToken != null)
UpdateGoogleClientAuthToken(updateClientAuth);
//Get the response body
var responseBody = "Error=";
try { responseBody = (new StreamReader(webResp.GetResponseStream())).ReadToEnd(); }
catch { }
//Handle the type of error
if (responseBody.StartsWith("Error="))
{
var wrErr = responseBody.Substring(responseBody.IndexOf("Error=") + 6);
switch (wrErr.ToLower().Trim())
{
case "quotaexceeded":
result.ResponseStatus = MessageTransportResponseStatus.QuotaExceeded;
break;
case "devicequotaexceeded":
result.ResponseStatus = MessageTransportResponseStatus.DeviceQuotaExceeded;
break;
case "invalidregistration":
result.ResponseStatus = MessageTransportResponseStatus.InvalidRegistration;
break;
case "notregistered":
result.ResponseStatus = MessageTransportResponseStatus.NotRegistered;
break;
case "messagetoobig":
result.ResponseStatus = MessageTransportResponseStatus.MessageTooBig;
break;
case "missingcollapsekey":
result.ResponseStatus = MessageTransportResponseStatus.MissingCollapseKey;
break;
default:
result.ResponseStatus = MessageTransportResponseStatus.Error;
break;
}
throw new MessageTransportException(wrErr, result);
}
else
{
//Get the message ID
if (responseBody.StartsWith("id="))
result.MessageId = responseBody.Substring(3).Trim();
}
}
}
catch (WebException webEx)
{
var webResp = webEx.Response as HttpWebResponse;
if (webResp != null)
{
if (webResp.StatusCode == HttpStatusCode.Unauthorized)
{
//401 bad auth token
result.ResponseCode = MessageTransportResponseCode.InvalidAuthToken;
result.ResponseStatus = MessageTransportResponseStatus.Error;
throw new InvalidAuthenticationTokenTransportException(result);
}
else if (webResp.StatusCode == HttpStatusCode.ServiceUnavailable)
{
//First try grabbing the retry-after header and parsing it.
TimeSpan retryAfter = new TimeSpan(0, 0, 120);
var wrRetryAfter = webResp.GetResponseHeader("Retry-After");
if (!string.IsNullOrEmpty(wrRetryAfter))
{
DateTime wrRetryAfterDate = DateTime.UtcNow;
if (DateTime.TryParse(wrRetryAfter, out wrRetryAfterDate))
retryAfter = wrRetryAfterDate - DateTime.UtcNow;
else
{
int wrRetryAfterSeconds = 120;
if (int.TryParse(wrRetryAfter, out wrRetryAfterSeconds))
retryAfter = new TimeSpan(0, 0, wrRetryAfterSeconds);
}
}
//503 exponential backoff, get retry-after header
result.ResponseCode = MessageTransportResponseCode.ServiceUnavailable;
result.ResponseStatus = MessageTransportResponseStatus.Error;
throw new ServiceUnavailableTransportException(retryAfter, result);
}
}
}
return result;
}
i am stuck here please help me.
is any thing i am missing
Have you signed up for the C2DM service and put your personal key in? http://code.google.com/android/c2dm/signup.html
The code you are receiving is documented here:
http://code.google.com/android/c2dm/index.html#push
P.S. I obtained both of these links from here: https://github.com/Redth/C2DM-Sharp Under the How do I use it? and Links sections.

Categories