WebService status?

C

Cralis

Hi guys,

I am using a normal ASP.Net Web Service. I make a call to my
webservice from a WinForms app, and displaying a message in the status
bar indicating that the app is communicating. It's very static
though.. just says 'Communicating'.

Is there a way to make it change? Like maybe a ... animating after the
words?

Also, there a way to change the text to 'Recieving...' when the web
service is bust replying?

So... 'Sending...' when the request is being sent, and 'Replying..'
when the web service is returning the data?
 
J

Jason Keats

Cralis said:
Hi guys,

I am using a normal ASP.Net Web Service. I make a call to my
webservice from a WinForms app, and displaying a message in the status
bar indicating that the app is communicating. It's very static
though.. just says 'Communicating'.

Is there a way to make it change? Like maybe a ... animating after the
words?

Also, there a way to change the text to 'Recieving...' when the web
service is bust replying?

So... 'Sending...' when the request is being sent, and 'Replying..'
when the web service is returning the data?

You need to use an asynchronous call to your web service.

http://www.codeproject.com/KB/vb/backgroundworker.aspx
http://msdn.microsoft.com/en-us/library/ms993020.aspx
http://ondotnet.com/pub/a/dotnet/2005/08/01/async_webservices.html
 
C

Cralis

Thanks Jason, I have implimented threading, so my GUI thread is free
while the WS does it's thing. Here's my current implimentation:

private void PerformWebServiceAction(CommRequest commRequest)
{
Common.WriteLog("Sending Web Service Request - " +
commRequest.CommandRequest);
if (_webServiceState == WebServiceState.SLEEPING)
{
tsWsStatus.ForeColor = Color.Red;
tsWsStatus.Text = "Communicating... >>";
_webServiceState = WebServiceState.REQUEST_PENDING;
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += PerformWebServiceActionDoWork;
worker.RunWorkerCompleted +=
PerformWebServiceActionComplete;
worker.RunWorkerAsync(commRequest);
}
else
{
Common.WriteLog("Cannot initiate Web Service call as
there is a result pending.");
if (commRequest.GetParameterValue("SilentCheck") ==
"0")
{
MessageBox.Show(
"Unable to do a " + commRequest.CommandRequest
+ " at the moment, as there is a request already in progress,\r\n\r
\nPlease try again in a few moments.", commRequest.CommandRequest,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}




The actual work is then done in this method in the worker thread:


private void PerformWebServiceActionDoWork(object sender,
DoWorkEventArgs e)
{
CommRequest commRequest = (CommRequest)e.Argument;
CommsService cs = new CommsService();
cs.Timeout = 15000;

try
{
CommRequest reply = cs.Request(commRequest);
reply.CommunicationResult = true;
e.Result = reply;
}
catch (Exception ex)
{
Common.WriteLog("\t\tERROR: Failed to make WebService
call. " + ex.Message);
_webServiceState = WebServiceState.SLEEPING;
commRequest.CommunicationResult = false;
commRequest.CommunicationError = ex.Message;
e.Result = commRequest;
}
}



And then when the WS completes, this method is used to handle the
reply:



private void PerformWebServiceActionComplete(object sender,
RunWorkerCompletedEventArgs e)
{
_webServiceState = WebServiceState.SLEEPING;
tsWsStatus.ForeColor = Color.Black;

tsWsStatus.Text = "Inactive";
CommRequest commRequest = (CommRequest)e.Result;

switch (commRequest.CommandRequest)
{
case "CHECK_IS_LATEST_FIRMWARE":
{
ProcessFirmwareReply(commRequest);
break;
}
case "REQUEST_NEW_DEVICE_UID":
{
ProcessNewDeviceUidRequest(commRequest);
break;
}

case "REGISTER_NEW_DEVICE_UID":
{
ProcessDeviceRegistration(commRequest);
break;
}
case "DOWNLOAD_FIRMWARE":
{
ProcessFirmwareDownload(commRequest);
break;
}
case "CHECK_IS_LATEST_SOFTWARE":
{
ProcessSoftwareReply(commRequest);
break;
}


default:
{
Common.WriteLog("\tError: Recieved a Service
Request reply, with a CommandRequest [" + commRequest.CommandRequest +
"] that is unhandled.");
break;
}
}

}


That is all working 100%
But, I'd like the status bar to change when the reply starts, as when
I do a request, the request may take 2 seconds, and the reply takes
between 2 seconds and 10 seconds, depending on what it's doing. So I'd
like a visual indication as to what state the WS request is in.
 
J

Jason Keats

Cralis said:
Thanks Jason, I have implimented threading, so my GUI thread is free
while the WS does it's thing. Here's my current implimentation:

I don't know if you looked at the links I provided, but they show two
different ways of calling a webservice and providing feedback.

It looks like you're using the method shown in the first link I provided
- making a synchronous call to a webservice from an asynchronous
background worker thread.

You've implemented events for DoWork and RunWorkerCompleted, but have
forgotten about ProgressChanged.

It's ProgressChanged that provides information to your GUI about
percentage completion.

See the (VB) example in the first link. :)

Alternatively, you could rewrite the whole thing to use AsyncCallback
(discussed in the second link).

BTW, there is nothing special about those links. They're just the first
that showed up when I searched for information on asynchronous web
service calls using C# - to give you somewhere to start.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top