Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Web services in .NET console and Form

Hi,

I've encountered the following problem with console applicaiton calling web service. If I call the Web Service asynchronously it works ok as many times as I want. But if I add just the following line Form f = new Form(); - i.e. create a class that is a Form or inherits Form, then the async calls do not work any more - the completion call back is never called. Any suggestions? I'm attaching here a very simple source that reproduces the problem. Note the Form f = new Form line. If I comment it out - then the second call to Web Service returns ok. If is not commented the second call not completed - i.e. the DataCallBack is never called.

using System;
using TestWebServiceConsoleApplication.com.eoddata.ws;
using System.Threading;
using System.Windows.Forms;


namespace TestWebServiceConsoleApplication
{
class Program
{

public com.eoddata.ws.Data service = null;
string token = null;

static void Main(string[] args)
{

//create class
Program p = new Program();

//create web service proxy
p.service = new com.eoddata.ws.Data();

//perform synchronous login
p.Login("user", "password");

//invoke async. method
p.GetSymbolHistory();

//just wait for 30 sec. - didn't want to make this more complex with events
Thread.Sleep(30000);

[b] //THIS LINE IS THE TROUBLEMAKER!!! if you comment it out - the next call will be successful
Form f = new Form();[/b]

//invoke the async. method again.
p.GetSymbolHistory();

//wait for the call back. Without Form f = new Form() line the answer to call back arrives quite in time - about few second later.
Thread.Sleep(3000000);

}


//login
public string Login(string userName, string password)
{
string token = null;

LOGINRESPONSE response = service.Login(userName, password);
if (!string.IsNullOrEmpty(response.Token))
{

token = response.Token;
service.SymbolHistoryPeriodByDateRangeCompleted += new SymbolHistoryPeriodByDateRangeCompletedEventHandler(DataCallback);
System.Console.WriteLine("Login successful " + token);
}

this.token = token;


return token;
}


public void GetSymbolHistory()
{
service.SymbolHistoryPeriodByDateRangeAsync(this.token, "NYSE", "X", "20111117", "20111118", "1", null);
System.Console.WriteLine("Request sent");
}

private void DataCallback(object sender, SymbolHistoryPeriodByDateRangeCompletedEventArgs args)
{

try
{
if (args.Cancelled)
{
System.Console.WriteLine("Cancelled");
return;
}

if (args.Error != null)
{
System.Console.WriteLine(args.Error.ToString());
return;
}

RESPONSE response = args.Result;

if ((response.Message != "Success")
&& (response.Message != "No data available")
&& (response.Message != "Invalid Exchange Code")
)
{
System.Console.WriteLine("Error getting response");
}
else
{
System.Console.WriteLine("Got response!!!");
}


}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}

}
}
Sign In or Register to comment.