xsharp.eu • Write a web service
Page 1 of 2

Write a web service

Posted: Wed Jun 12, 2019 4:10 pm
by softdevo@tiscali.it
Has anyone written a web service with XSharp? any ideas / suggestions / examples?
Thank you all

Danilo

Write a web service

Posted: Wed Jun 12, 2019 5:33 pm
by Jamal
Hi Danilo,

I might not be right, but I have not seen a way to design web services in X#.

I expected that X# may compile the following code, but it errors on [WebMethod].

Dev team, any comment?

Code: Select all

CLASS MathServices
 
    CONSTRUCTOR()
         RETURN
            
            
    [WebMethod]
    public function Add(a as int, b as int) as int
    
       return(a + b)
    
  
END CLASS
Furthermore, you cannot "Add Service Reference" to a program References like C#.

Jamal

Write a web service

Posted: Wed Jun 12, 2019 5:50 pm
by softdevo@tiscali.it
For greater clarity.
I must be able to ask a web server for information such as the values contained in a database table or for example to receive in XML format the result of a processing performed on the web server.

Danilo

Write a web service

Posted: Wed Jun 12, 2019 5:55 pm
by robert
Jamal,
There is a semi colon missing after the attribute, and you should name it Method in stead of Function

Code: Select all

[WebMethod];
    public method Add(a as int, b as int) as int
Robert

Write a web service

Posted: Wed Jun 12, 2019 6:15 pm
by Jamal
Robert,

Thanks, I modified the code and added some comments.

Code: Select all

USING System
USING System.Collections.Generic
USING System.Text

using System.Web.Services    // need this reference

BEGIN NAMESPACE xSharpWinFormsApp1

 
   CLASS MathServices
 
    CONSTRUCTOR()
         RETURN
            
            
    [WebMethod];      // semi colon needed (strange X# requirement)
    public method Add(a as int, b as int) as int    
       return(a + b)
      
   END CLASS
END NAMESPACE
And here is how it is called:

Code: Select all

    LOCAL ws :=  MathServices{} as MathServices
        
    MessageBox.Show(ws:Add(1,2).ToString())   // result 3
Jamal

Write a web service

Posted: Wed Jun 12, 2019 6:18 pm
by Jamal
I think you are talking about consuming a web service and generating class via the Add Service Reference.

Robert, why is it missing and is there a plan to implement it (C# screenshot below)?
6-12-2019 12-55-10 PM.jpg
6-12-2019 12-55-10 PM.jpg (40.54 KiB) Viewed 1263 times

Write a web service

Posted: Wed Jun 12, 2019 7:08 pm
by robert
Jamal,
The semi colon is needed because the CRLF after [WebMethod] is a statement delimiter. By adding the semi colon the attribute belongs to the following line.
You can also write
[WebMethod] public method Add()

Robert

Write a web service

Posted: Wed Jun 12, 2019 7:09 pm
by robert
Jamal,

I will see of I can add this (Add Service Reference) in the X# project system.

Robert

Write a web service

Posted: Wed Jun 12, 2019 7:56 pm
by NickFriend
Hi Danilo,

I haven't done it with X#, but with C# we use web services running under WCF. This works very well, and I can't see any reason why it couldn't be done with X#. Stuff like serialisation of data transmitted is all handled automatically, so once you've got it up and running it's very easy to use.

Nick

Write a web service

Posted: Wed Jun 12, 2019 11:00 pm
by lumberjack
Hi Nick/Danilo
NickFriend wrote:Hi Danilo,
I haven't done it with X#, but with C# we use web services running under WCF. This works very well, and I can't see any reason why it couldn't be done with X#. Stuff like serialisation of data transmitted is all handled automatically, so once you've got it up and running it's very easy to use.
I have never done a X# web service directly, but have done web services with a c# wrapper that actually have X# code behind. No problem in consuming web services from a X# application, even through dynamic HttpRe<classname> calls. Cannot comment about aspx web front-ends though... But the back-end can be X#.