Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Write a web service 12 Jun 2019 18:10 #9266

  • softdevo@tiscali.it's Avatar
  • Topic Author


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

    Danilo

    Please Log in or Create an account to join the conversation.

    Write a web service 12 Jun 2019 19:33 #9274

    • Jamal
    • Jamal's Avatar


  • Posts: 309
  • 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?

    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

    Please Log in or Create an account to join the conversation.

    Last edit: by Jamal.

    Write a web service 12 Jun 2019 19:50 #9275

    • softdevo@tiscali.it's Avatar
    • Topic Author


  • Posts: 177
  • 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

    Please Log in or Create an account to join the conversation.

    Write a web service 12 Jun 2019 19:55 #9277

    • robert
    • robert's Avatar


  • Posts: 3600
  • Jamal,
    There is a semi colon missing after the attribute, and you should name it Method in stead of Function
    [WebMethod];
        public method Add(a as int, b as int) as int

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Last edit: by robert.

    Write a web service 12 Jun 2019 20:15 #9278

    • Jamal
    • Jamal's Avatar


  • Posts: 309
  • Robert,

    Thanks, I modified the code and added some comments.
    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:
        LOCAL ws :=  MathServices{} as MathServices
            
        MessageBox.Show(ws:Add(1,2).ToString())   // result 3

    Jamal

    Please Log in or Create an account to join the conversation.

    Last edit: by Jamal.

    Write a web service 12 Jun 2019 20:18 #9279

    • Jamal
    • Jamal's Avatar


  • Posts: 309
  • 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)?

    Please Log in or Create an account to join the conversation.

    Last edit: by Jamal.

    Write a web service 12 Jun 2019 21:08 #9281

    • robert
    • robert's Avatar


  • Posts: 3600
  • 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

    Please Log in or Create an account to join the conversation.

    Write a web service 12 Jun 2019 21:09 #9282

    • robert
    • robert's Avatar


  • Posts: 3600
  • Jamal,

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

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Last edit: by robert.

    Write a web service 12 Jun 2019 21:56 #9283

    • NickFriend
    • NickFriend's Avatar


  • Posts: 246
  • 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

    Please Log in or Create an account to join the conversation.

    Write a web service 13 Jun 2019 01:00 #9288

    • lumberjack
    • lumberjack's Avatar


  • Posts: 721
  • 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#.
    ______________________
    Johan Nel
    Boshof, South Africa

    Please Log in or Create an account to join the conversation.

    Write a web service 13 Jun 2019 08:25 #9294

    • softdevo@tiscali.it's Avatar
    • Topic Author


  • Posts: 177
  • The reason is that I have to run complex code of my application and then return the result as an xml file.
    So to summarize, if I understand correctly, the call to the web service takes place through the public method contained in the CLASS MathServices, which can return values of any type; and to return a file? it's possible? I imagine so.

    thank you to all.

    Danilo

    Please Log in or Create an account to join the conversation.

    Write a web service 13 Jun 2019 10:16 #9298

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3367
  • Hi Danilo,

    it is also possible to write an X# service and respond directly to the requests.

    You can find a sample here:
    www.riedmann.it/download/VulcanHttpListener.viaef

    I'm using an application based on this sample for several years now on a customers server. The beauty of this solution is that you don't need anything special, as it does not needs any webserver, but uses http.sys that is part of every Windows installation.
    The bad notice is that you have to do all by yourself - every input and output processing. This may be to much for a complex website, but is ok for a webservice, where the frontend could be built by a normal webserver.

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Write a web service 13 Jun 2019 10:21 #9299

    • lumberjack
    • lumberjack's Avatar


  • Posts: 721
  • wrote: The reason is that I have to run complex code of my application and then return the result as an xml file.
    So to summarize, if I understand correctly, the call to the web service takes place through the public method contained in the CLASS MathServices, which can return values of any type; and to return a file? it's possible? I imagine so.
    thank you to all.

    Danilo, am I correct in assuming you have a desktop client that you want to interface to a webservice?
    In that case google WSDL, you will find how to create a "local" client for the webservice that you link into your application which will have all the interfaces to communicate with the webservice, no worry about having to convert to xml etc.

    Attached a class that I wrote in the Vulcan days to create a c# assembly that you can then use to communicate with the webservice.

    Hope this helps.

    File Attachment:

    File Name: jhnWSDL.zip
    File Size:2 KB
    ______________________
    Johan Nel
    Boshof, South Africa
    Attachments:

    Please Log in or Create an account to join the conversation.

    Write a web service 13 Jun 2019 11:31 #9300

    • softdevo@tiscali.it's Avatar
    • Topic Author


  • Posts: 177
  • Thank you Wolfgang, Precious as usual

    Danilo

    Please Log in or Create an account to join the conversation.

    Write a web service 13 Jun 2019 11:35 #9301

    • softdevo@tiscali.it's Avatar
    • Topic Author


  • Posts: 177
  • I have to provide information processed by my web application, written in XSharp, to an app that will run on an Android or Apple smartphone

    Danilo

    Please Log in or Create an account to join the conversation.

    Write a web service 13 Jun 2019 12:07 #9302

    • lumberjack
    • lumberjack's Avatar


  • Posts: 721
  • wrote: I have to provide information processed by my web application, written in XSharp, to an app that will run on an Android or Apple smartphone

    The only thing you have to do is to [WebMethod] what you want exposed with a return type, the web server (IIS, Apache) will handle the rest of converting to xml and pass to the client.
    ______________________
    Johan Nel
    Boshof, South Africa

    Please Log in or Create an account to join the conversation.

    Write a web service 13 Jun 2019 22:18 #9319

    • Jamal
    • Jamal's Avatar


  • Posts: 309
  • Hi Johan,

    To be able the access the web service, CORS has to be setup properly in the Global.asax file and the a Public Interface has to be created as [ServiceContract] and each method has to be declared, but then I found WCF generation in X# is not correct (it's generating X# and C# code!!). Please see my other post (WCF generation incorrect). Also, It seems now there is no X# template to create a web application, so WCF in X# right may not be ready. I did not see it in the 2019 Road Map.

    Jamal

    Please Log in or Create an account to join the conversation.

    Last edit: by Jamal.
    • Page:
    • 1