Write a web service

This forum is meant for examples of X# code.

User avatar
softdevo@tiscali.it
Posts: 189
Joined: Wed Sep 30, 2015 1:30 pm

Write a web service

Post by softdevo@tiscali.it »

Has anyone written a web service with XSharp? any ideas / suggestions / examples?
Thank you all

Danilo
Jamal
Posts: 314
Joined: Mon Jul 03, 2017 7:02 pm

Write a web service

Post 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
User avatar
softdevo@tiscali.it
Posts: 189
Joined: Wed Sep 30, 2015 1:30 pm

Write a web service

Post 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
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Write a web service

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
Jamal
Posts: 314
Joined: Mon Jul 03, 2017 7:02 pm

Write a web service

Post 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
Jamal
Posts: 314
Joined: Mon Jul 03, 2017 7:02 pm

Write a web service

Post 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 1193 times
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Write a web service

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Write a web service

Post by robert »

Jamal,

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

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

Write a web service

Post 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
User avatar
lumberjack
Posts: 723
Joined: Fri Sep 25, 2015 3:11 pm

Write a web service

Post 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#.
Post Reply