Calling Web Methods
From Morfikwiki.com
Calling Web Methods in your application is quite simple. The following listing shows the code for a Form from which a Web Method call is made. In this case it is a simple method that returns a list of names and phone numbers.
The actual results are returned through a call back routine which is assigned to an event of the Web Method class, when it is instantiated. The logic for this example is that when a button is clicked a Web Method is called which returns a the list of data. When the data is received, in a browser side callback routine, it is added to the contents of a simple TextEdit control.
You can see the server implementation of this Web Method in a listing in the Creating Web Methods - In code topic.
Unit Content;
Interface
uses PhoneBookServerService;
Type
Content=Class(Form)
Button1 : Button;
TextEdit1 : TextEdit;
Procedure Button1Click(Event: TDOMEvent); Message;
Private
{ Private declarations }
Public
{ Public declarations }
procedure HandleContacts(WM:TListContacts);
End;
Implementation
procedure Content.HandleContacts(WM:TListContacts);
Var
I: integer;
begin
If WM.MyContacts.Count > 0 then
For I := 0 to WM.MyContacts.Count-1 do
TextEdit1.Text := TextEdit1.Text + WM.MyContacts[I].Name +':'+ WM.MyContacts[I].Phone;
WM.Free;
end;
Procedure Content.Button1Click(Event: TDOMEvent);
var
ListContacts: TListContacts;
Begin
ListContacts := TListContacts.Create;
ListContacts.OnWebMethodReturn := @HandleContacts;
ListContacts.Execute;
End;
End.
| Note | |
| This code only works in the Browser side portion of a Morfik AppsBuilder project, at this time. This code will not work in a Browser Application project. | |
When you are calling Web Methods created within the same project you can use the RunWebMethod command. In this case, you will need to write code in the HandleResponse Method of the browser version of your Web Method class to process the return values.
The following is a sample call to the RunWebMethod command:
RunWebMethod('AuthenticateUser','"AUserName='+ UserNameEdit.Text + '", "APassword=' + PasswordEdit.Text + '"');

