Calling web-service from Axapta

D

dzeaman

Hi all

I try to call the web-method, which works too long time.
Is there any variants how to stop the web-service by, e.g., clicking "Stop"
button on the custom form?

Also it's interesting to know, if I can organize "callback" (I want Axapta
to display what web-service do in real-time or something like real-time).

Thank you for your comments.
 
D

dzeaman

I didn't wait till replies but maybe my experience will be helpful for someone.

I organize both "Stop"-button and CallBack.
First I found the article of Matt Powell "Server-side asyncronous
web-methods". He advice to use BeginInvoke and EndInvoke for
delegate-methods. But I didn't found how to stop delegate in runtime.

So I try to use method that is not described in MSDN for web-services. Of
course, I didn't invent something new. I just use threading.

First of all I created the private-class TestThread with methods start(),
init() and getResult(). Disadvantage of this method is that you can't send
parameters directly into method, so you need to create init() method for that.

Than I created the thread and web-methods start(), result(), isAlive() and
abort(). Here're they:

private static TestThread testThread;
public static Thread thread;

[WebMethod]
public bool start( string _param )
{
testThread = new TestThread();
testThread.init( _param );
thread = new Thread( new ThreadStart( testThread.start ) );
thread.Start();
return true;
}

[WebMethod]
public bool result()
{
return testThread.getResult();
}

[WebMethod]
public bool isAlive()
{
return thread.IsAlive;
}

[WebMethod]
public bool abort()
{
thread.Abort();
return true;
}

I realize you'll understand this idea.



Callback is also not so hard.

private static ProcessInfo processInfo;

[WebMethod]
public string getProcessInfo()
{
return processInfo.getInfo();
}

And the class:

public class ProcessInfo
{
private static string info;

public string getInfo()
{
string result = info;
info = "";
return result;
}

public string addInfo( string _info )
{
info += _info;
return info;
}
}

That's all.

Best regards,
Andrey Dzizenko.
 

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

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top