locked
Tutorial for beginner in xml webservice RRS feed

  • Question

  • User377686606 posted

    I´m new to webservices and i havent found or don´t know how to ask what i need to know.

    So far i´ve been able to create a webservice with methods connected to a database and a client to consume simple data. 

    Can you point a guide to generate a xml file and download it to the client?

    I´m using VS 2013 and VB.

    Thanks in advance!

    Thursday, July 23, 2015 2:51 PM

All replies

  • User753101303 posted

    Hi,

    A high level view could help. Do you really need an XML file? When using Web services XML can be used being the scene but converting to and from XML is done for you so you just deal with the data you need.

    Thursday, July 23, 2015 2:57 PM
  • User377686606 posted

    Thanks for your reply. 

    The idea is to download xml from a webservice and store those xml into a client. Then a disconnected windows form app reads and write into the xml. Once the user has restored connection data is sent to the web service. 

    Maybe there is another better way.  I´m open to suggestions. Smile

    Thursday, July 23, 2015 3:08 PM
  • User61956409 posted

    Hi contumaz,

    In this blog,  the author explained how to create and return xml document from a web service, please refer to it.

    http://www.ashishblog.com/how-to-create-and-return-xml-document-from-a-web-service-c-net/

    Best Regards,

    Fei Han

    Friday, July 24, 2015 1:46 AM
  • User377686606 posted

    Thanks a lot. I´m going to read it and try it.Laughing

    Friday, July 24, 2015 7:22 AM
  • User377686606 posted

    Hi guys! 

    I´ve been able to get the xml, but when it´s too large i get an error;

    "The following elements are not closed: Num, Nem"

    I fully understand that this means that my xml is missing closing tags. But when i look the xml that the sql sp produces there is no missing tags. 

    i checked the XmlDocument class to see if i have to set any aditional method or method lenght to be set but there is no such thing,

    Thanks in advance guys!

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Data.SqlClient;
    using System.Data;
    using System.Xml;
    
    namespace WebServerTerrenoC
    {
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // [System.Web.Script.Services.ScriptService]
        public class TerrainWebService : System.Web.Services.WebService
        {
    
            [WebMethod]
            public XmlDocument DataSearch(string tecnico)
            {
            string xml = "<Products></Products>";//<Product><Name>Not Found</Name></Product></Products>";
            try
            { 
                using (SqlConnection con = new SqlConnection(configuracion.CadenaConexion))
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("XmlTerreno", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@tecnico", tecnico));
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        xml = dr[0].ToString();
                    }
                    con.Close();
                }
            }
            catch (Exception) { }
          
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(xml);
                return xmlDoc;        
            
        }        
    
        }
    }
    

    Monday, July 27, 2015 11:38 AM
  • User-1926401737 posted

    Hi contumaz,

    Your problem is related to WebService, so you could post the problem in this forum.

    https://forums.asp.net/28.aspx

    With Regards,

    swing

    Wednesday, August 5, 2015 5:18 AM