[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to send an XML file/data from a windows service to a web service?

Posted on 2004-09-09
7
Medium Priority
?
251 Views
Last Modified: 2008-02-01
Hi,
 I am setting up a windows service that will send xml data to a web service on a timed interval.  The xml data is a dataset from the sql server.  What is the best way to transport this xml data to the web service?  Will I be using SOAP? Or just use WebMethods?

Lastly, how can I stream the xml data from windows service to the web service securely?  

I am new at this, so any help would be appreciated.  Furthe more, the transport method must be secured.  

Any suggestions, links, info, code,  would help.

Thanks,
 
K
0
Comment
Question by:Khaki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 10

Expert Comment

by:jnhorst
ID: 12024165
The security issue should be handled by the web service.  It should accept SOAP via the https protocol.  If you have control over the web service (meaning you are programming it), you can set that up or you can write up your own encryption before you send off the XML and then decrypt it in the web service.  But again, that is if you have control over the web service.

By your question about web methods, I am thinking you will be developing the web service.  If this is true, then yes, you would define a web method that would accept your dataset as its argument.  In the consuming application, you set a Web Reference with the URL for the web service and then call its web methods just like calling the methods of any other class.

If you are going to create the web service and need some code samples, post a comment accordingly and I'll try to gin something up for you.

John
0
 

Author Comment

by:Khaki
ID: 12028353
Hi John, Thanks for insight.  I think you got were I am going.  I will be writing both the client and the web service, so if you have any sample code, I would greatly appreciated it.  
 One more thing, do you have any sample SOAP working  https links or samples?  I just need something small, then I can get started on my own.

Thanks.

K
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12032009
I don't, but you don't really need that.  ASP.NET abstracts the complexity of SOAP away from the developer quite nicely.  You create the webservice and ASP.NET takes care of creating the SOAP envelope.  On the consuming side, you set w "Web Reference" and ASP.NET creates the SOAP to call the web method and pass the dataset.

I'll gin up a real simple web service and explain how to do the same.  I'll post this (hopefully) by the end of the evening.

John
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 10

Accepted Solution

by:
jnhorst earned 640 total points
ID: 12032472
Khaki:

OK:  Start by creating a new project.  Select the ASP.NET Web Service icon in the dialog and name it something like WebServicesTest.  The location of the project should be http://localhost/WebServicesTest.

VS will create a default file named Service1.asmx.  Change the file name to XtremeData.asmx.  Then right click the file and select View Code.  You will see class defined as Service1.  Change it to XtremeData.  If you are using C#, make sure to change the constructor method name to XtremeData as well.  Build the project.

Now go to the Server Explorer in the VS IDE.  There is a toolbar button on the upper right of the IDE that drops down.  You will find the Server Explorer there.  In the server explorer right click on the Database Connections node and select Add Connection.  If the Provider tab is not selected, select it and pick the "Microsoft OLE DB Provider for ODBC Drivers" and click Next.  You will be asked to select the ODBC datasource.  There should be an ODBC data source for the Xtreme database already on your system.  Choose it.  There will also be a dropdown for Initial Catalog.  This should have the file path.  Select it and test the connection.  It should be fine.

This is a database used for Crystal Report samples, but it will suffice for our purposes.  You'll see nodes for Tables and Views.  Expand the Tables node.  Then in the VS menu click Project >> Add New Item.  Select the dataset icon and change the file name to Xtreme.xsd.  You will see a blank yellowish designer.  Drag the Employee table node onto this designer.  You will see a box with the Employee table's columns and their data type.  Technically, in XML this is called an element, and the columns are elements within the Employee element.  But ADO.NET will use this to create a class named Xtreme that inherits from System.Dataset with a DataTable named Employee created from the XML elements defined in the Xtreme.xsd file.  This is the dataset you will populate and return to your consuming app.  Build the app to make sure everything is set up right.

Now make sure the XtremeData.asmx file is showing in design view (should be an empty light bluesh pane).  Open your toolbox and click the Data tab.  Doublic click the Dataset tool.  You'll get a dialog that will have a "Typed Dataset" radio button selected and the Xtreme dataset in a dropdown.  Just click OK.  An icon will appear in the designer with the name xtreme1.  Right click it, show its properties and change its name to dsXtreme.  Save your project.  Again in the Data tab of the toolbox, double click OdbcDataAdapter.  You will get a Data Adapter Configuration Wizard (this is one very cool IDE feature).  Click next.  Unless you have other connections in the Server Explorer, your Access connection will appear in the dropdown.  It it isn't, select it and click next.  You will only be able to use SQL statements so click Next again.  Enter the following:

Select * From Employee

(It is generally bad form to use "Select *" like this, but for demo purposes, it'll do.)  CLick the Advanced Options button and deselect the "Generate Insert, Update and Delete Statements" checkbox and click OK.  Click Next.  You should see "Generated Select Statement" and "Generated Table Mappings" with checks next to them.  Click Finish.  Right click the icon in the designer and change the name to daXtreme.  Now we'll do the web method.

In the code for the XtremeData.asmx file, enter the following (within the class):

[WebMethod]
public WebServicesTest.Xtreme GetEmployees()
{
      this.daXtreme.Fill(this.dsXtreme.Employee);
      return this.dsXtreme;
}

Here you are simply filling the datatable and returning it within the dataset.

Build the project.  Your webservice is basically done.

Now, in the same solution, create a ASP.NET Web Application project and name it WebServiceConsumer.  Right click the project node and set the project as the startup project.  It will create a WebForm1.aspx file.  We'll use that to call to the web service.  But you will first need to set a Web Reference.  In the Web References node in this new project, right click References and select Add Web Reference.  You will get a dialog asking for the URL to your web service.  This will be:

http://localhost/WebServicesTest/XtremeData.asmx.  The dialog will tell you that it found the service and will show you what methods it exposes, which will be GetEmployees().  Change the Web Reference Name to WebServicesTest and click Add Reference.  Bulid your consuming application.  Open the WebForm1.aspx page in design view.  Doublie click the Dataset tool in the Data toolbox tab like before.  It will recognize that the web service exposes the Xtreme dataset.  Leave this selected and click OK.  An icon will appear the bottom of the page in design mode in a tray.  Right click it, show proprties and change the name to dsXtreme.

Now put a datagrid on the page and set the DataSource to dsXtreme and the DataMember to Employee.  Rename the grid to grdXtreme. You'll see all of the columns in the grid, even in design time.  Now in the page's codebehind, in Page_Load, do this:

private void Page_Load(object sender, System.EventArgs e)
{
      // get dataset.
      WebServicesTest.XtremeData ws = new WebServicesTest.XtremeData();
      this.dsXtreme = ws.GetEmployees();

      if (!this.IsPostBack)
      {
            this.grdXtreme.DataBind();
      }
}

Now comes the cheesy part.  When you opened your connection in Server Explorer, Access locked the mdb file so if you run the app now, you'll get an error.  Close down VS and restart it.  This will release the lock.  Start the app.  Your WebForm1.aspx should load and show the data from the Xtreme database in your grid.

This is the basics of creating and consuming a web service.  You can have multiple services in one project.  You'll have to figure out the security part, but if your server supports https, that should do what you need by way of encryption.

John
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12032502
Sorry, there is no "Web References" node.  Just References.  Right click and add a Web Reference.

John
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12032512
Also, if you could bump up the points a little, that would be cool.  But that's up to you.

John
0
 

Author Comment

by:Khaki
ID: 12035437
good job. That will get me started.
Thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question