[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

create webservice

i need to create a simple webservice that will pick up 2 columns from my sql server db and create an xml file.  
my query is "select lat,lng,info from table"
my xml file needs to look like sample below.

please any ideas?

<markers>
     <marker lat="43.65654" lng="-79.90138" label="Marker One">
      <infowindow><![CDATA[
        Some stuff to display in the<br>First Info Window
      ]]></infowindow>
     </marker>
   </markers>
0
gianitoo
Asked:
gianitoo
  • 5
  • 4
1 Solution
 
Saqib KhanSenior DeveloperCommented:
Why cant you just have a Function in your WebService & then Create a String within your function which will build the XML output, and then have your Function return that String.
0
 
gianitooAuthor Commented:
ok, do you have a sample code.  i am new with webservices
0
 
Saqib KhanSenior DeveloperCommented:
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.

 
gianitooAuthor Commented:
Ok I did, it does not tell me how to conect to my db and consume an xml file though.  
do you know how to accomplish this?
0
 
Saqib KhanSenior DeveloperCommented:
so that means, you never worked on a ASP.net Application that connects with the Database? if not then you gonna have to do alot of reading.

You need to start with how to Read data using Asp.net (Depending upon what data source you are using). once you know how to read data then you can use that technique within your WebService to return the XML string within Your Function.
0
 
gianitooAuthor Commented:
I do know how to connect.  i will add my connection tomorrow and return the data that i need.  
perhaps you can guide me a little.  
I am about to head home.  
0
 
Saqib KhanSenior DeveloperCommented:
sure.

Import your data provider Namespace.
Connect to your DB
Write a Function to retuen results
Then have that Function String the Xml String.

any help let me know.
0
 
gianitooAuthor Commented:
      ok this connection below returns my data.  how can i shoot the xml file fom this data?

Dim conn As New Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("connectionUSSL"))
                   
        conn.Open()
        Dim cmd As New Data.SqlClient.SqlCommand("salesquoteschecker", conn)
        cmd.CommandType = CommandType.StoredProcedure

        cmd.Parameters.Add("@ID", SqlDbType.Int).Value = Request.QueryString("id").ToString()
        Dim dr As Data.SqlClient.SqlDataReader = Nothing
 
        dr = cmd.ExecuteReader()
 
        While dr.Read()
 
            Session("longitude") = dr("longitude").ToString()
            Session("latitude") = dr("latitude").ToString()
Session("info") = dr("info").ToString()

       
           
        End While
 
        conn.Close()
        conn.Dispose()
0
 
Saqib KhanSenior DeveloperCommented:
Below needs to be in a WebService Function.

Dim conn As New Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("connectionUSSL"))
                   
        conn.Open()
        Dim cmd As New Data.SqlClient.SqlCommand("salesquoteschecker", conn)
        cmd.CommandType = CommandType.StoredProcedure

        cmd.Parameters.Add("@ID", SqlDbType.Int).Value = Request.QueryString("id").ToString()
        Dim dr As Data.SqlClient.SqlDataReader = Nothing
 
        dr = cmd.ExecuteReader()
  Dim longitude as double
  Dim latitude as double
  Dim info as string
  Dim xmlString as string = ""

        While dr.Read()
 
            longitude  = dr("longitude").ToString()
            latitude  = dr("latitude").ToString()
           info  = dr("info").ToString()

           xmlString = xmlString & "<xml><mytag value='"& longitude &"'></xml>"
           
        End While
 
        conn.Close()
        conn.Dispose()

    Return xmlString


so read the above article on how to create a method, then modify the xmlString  variable to create your string and then return it using that method.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now