Get all data from WebService in Magic XPA 3.2c


 

Hi, 

I have created my own WebService using c# with the following code: 
---------------------------------------------------------------------------------------------------------------- 
[WebMethod] 
public DataTable getAlltbEmpList() 

string constr = ConfigurationManager.ConnectionStrings["CustomerEntities"].ConnectionString; 
using (SqlConnection con = new SqlConnection(constr)) 

using (SqlCommand cmd = new SqlCommand("SELECT * FROM tbEmployee")) 

using (SqlDataAdapter sda = new SqlDataAdapter()) 

cmd.Connection = con; 
sda.SelectCommand = cmd; 
using (DataTable dt = new DataTable()) 

dt.TableName = "tbEmployee"; 
sda.Fill(dt); 
return dt; 





---------------------------------------------------------------------------------------------------------------- 

My concern is, how can I consume it on my created application in Magic XPA 3.2c? 

I'd like to output it in table form... 

(If this question is insufficient, just let me know) 

**Note: the webservice that has been created is completely working and no error.** 

Thank you in advance!


Andreas Sedlmeier
 

Hi Neil,

Add "?wsdl" (without quotes) to the URL of your service endpoint. That should return you the WSDL and that URL you can use for the Invoke Webservice Operation in Xpa.

Alternatively you can do the requests "by foot" with Magic HttpCall (or an alernative http client). Since you do however work with C# for the producer anyways, you could also simply put the client in a .NET class library (better) or Magic Xpa .NET Snipplet (worse). That saves you from a lot of headache later on when you start to secure your webservice, work with API tokens, ...

Best regards,

Andreas


 
Edited

Hi Andreas,

after invoking the wsdl what should i do next?

can you walk me through this? like step by step procedure?

I want to output it in a table form...

Thank you and I highly appreciate your help! :)

***By the way, I use WSLite to invoke my WSDL***


Andreas Sedlmeier
 

Hi Neil,

I have no Walk through, its however not that difficult.

Create a batch program or event handler and insert a "Invoke Web S Lite" operation. Double click it or zoom into it to get the WSDL selection.

There you can put your service endpoint followed by "?wsdl" and Magic will download the WSDL and list you the available operations (methods) . You should have a method named "getAlltbEmpList" there.

That you select and it will be of type (style) "Document". The method returns a XML document which you assign to a Blob (Unicode). That (XML Blob) you do read with XML direct access functions in another task where you have the XML Blob as a I/O entry of type Variable.

Write the result in a table (sqlite or memory) and you basically have what you want. You might also be able to use functionality of your DBMs to convert the XML to a (temporary table). 

If you cannot get that working I can provide you with a small sample, not before the weekend however.

Best regards,

Andreas



 
Edited

Hi Andreas,

I kinda get the procedure you said in the: "There you can put your service endpoint followed by "?wsdl" and Magic will download the WSDL and list you the available operations (methods) . You should have a method named "getAlltbEmpList" there."

but not much on the next procedure.

Thank you for this! And yes, kindly send me a small sample regarding to this situation to my email:
Email: ndeleon @ everywhereconsulting.com

Thank you & have a great day,

Neil


Andreas Sedlmeier
 

Hi Neil,

I created you a Magic XPA 3.3 sample, which is available (complete project + export file) here: https://github.com/asedl/XpaDemo/tree/master/Components/Samples/WsDemo . I have only Magic Xpa Single User which is Xpa 3.3. If you cannot import the project in a Xpa application of yours you'll have to downlaod Xpa Single User edition from MSE.

In the sample there's two programs:
GetAuthors which fetches a list of Authors from a .NET webservice method "ListAuthors"
Read_XML_Response which parses the XML response of the ws into a temp. table (sqlite)

For me this works fine, the code of the .NET ws method I paste below.

Good luck and best regards,

Andreas

==

namespace XpaDemoSrv
{
    /// <summary>
    /// Summary description for Books
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Books : System.Web.Services.WebService
    {
 
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
 
        [WebMethod]
        public DataTable ListAuthors() {
 
            // Create a DataTable with a name and add a few records ...
            DataTable dtAuthors = new DataTable(); 
            dtAuthors.Columns.Add("author_id");
            dtAuthors.Columns.Add("author_name");
            dtAuthors.TableName = "dtAuthors";
 
            DataRow newAuthor;
            newAuthor = dtAuthors.NewRow();
            newAuthor["author_id"] = "1";
            newAuthor["author_name"] = "James Joyce";
            dtAuthors.Rows.Add(newAuthor);
            newAuthor = dtAuthors.NewRow();
            newAuthor["author_id"] = "2";
            newAuthor["author_name"] = "Franz Kafka";
            dtAuthors.Rows.Add(newAuthor);
            newAuthor = dtAuthors.NewRow();
            newAuthor["author_id"] = "3";
            newAuthor["author_name"] = "Ernest Hemingway";
            dtAuthors.Rows.Add(newAuthor);
            newAuthor = dtAuthors.NewRow();
            newAuthor["author_id"] = "4";
            newAuthor["author_name"] = "Thomas Mann";
            dtAuthors.Rows.Add(newAuthor);
 
            return dtAuthors;
        }
    }
}


 

Hi Andreas,

I'll keep you posted regarding on my situation...

Thank you and have a great day ahead!

Best Regards,
Neil


Andreas Sedlmeier
 

Hi Neil,

So you managed to get that Xpa 3.3 project working ?

This is now how you would parse the response of a document style SOAP method into a temp. table in Magic. Thats a bit tedious as you will see.

There's however also the option to use .NET or Java to deserialize the response into (collection) objects and those you can use in Magic as well then - as is (together with all the nice methods and properties they have). Besides, if it's .NET you could even factor out the temp. table and create a .NET datasource from the response instead which you can use in Magic Xpa like a table (asfaik, cause I never did this).

If I find time later this week I'll add this to the sample and update the Magic App + C#/Java sources.

Best regards,

Andreas