Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# HTTP WebService
I am new to web services but basically i have created a webservice that reads from a db and then returns a value back to the client. Here is an example of my webservice.
 
namespace TestWebService1
{
    /// <summary>
    /// Summary description for Service1
    /// </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 Service1 : System.Web.Services.WebService
    {
 
        [WebMethod]
        [ScriptMethod(UseHttpGet=true)]
        public string getID()
        {
            SqlConnection cs = new SqlConnection(@"Server=130-ASQL1-B-001.OSCD.LOCAL;Initial Catalog=AIM;User ID=user;Password=pass");
 
            SqlCommand cmd = new SqlCommand("select id from NIM where stationName='" + System.IO.Path.GetDirectoryName(HttpContext.Current.Request.ServerVariables["REMOTE_USER"]) + "' and availability = 'reachable'", cs);
 
            cmd.CommandType = CommandType.Text;
 
            cmd.Connection = cs;
 
            cs.Open();
 
            SqlDataReader dr = cmd.ExecuteReader();
 

            dr.Read();
            
                return dr["id"].ToString();
 
                dr.Close();
                cs.Close();
  
            
        }
    }
}
 
Ok now I would like to call this web service from an html page
 
<div style="display: hidden;">
<form action='http://localhost:52618/Service1.asmx/HelloWorld?ID='
method="get" target="_self">
<table>
  <tr>
    <td>GET ID</td>
    <td>
    <input class="frmInput" type="text" size="30" name="id">
    </td>
  </tr>
  <tr>
    <td></td>
    <td align="right">
     <input type="submit" id="submitButton" value="Submit" class="button">
     </td>
  </tr>
</table>
</form>
<script language="javascript">
        document.getElementById("submitButton").click();
    </script>
</div>
 
the soap message that appears is below.
 
 
<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="http://tempuri.org/">0</string>
 
So far i am able to call the web service fine but what happens is it calls the web service and display the soap message on the webpage within the browser. I would like to somehow show the value of my soap message in the url like http://localhost:52618/Service1.asmx/HelloWorld?ID=42 or something like that. I know this can be done from the examples i've seen but i'm obviously not doing something right on either the web service or client side. Also i'm not exactly sure that this is the best way to call a web service from an html page so if anyone has any knowledge on that that would be great as well. I am having to use javascript but it would be nice just use html. Any Help is Appreciated!
Posted 21-Jun-13 19:09pm
Edited 24-Jun-13 5:34am
v3
Comments
Mahesh Bailwal at 23-Jun-13 4:56am
   
can you share your soap message.
Dustin Prevatt at 24-Jun-13 10:33am
   
adding the soap message...
eng.amir.ebrahimi at 23-Jun-13 6:07am
   
Read AJAX ...if you wanna call a webservice in your web application ...The best way is AJAX !
Dustin Prevatt at 24-Jun-13 10:35am
   
I need to find out a way to call this from a plain html page and somehow store the soap message data (which in this case is 0) to a variable or something so that it can be reused. Can i use ajax without it being an asp.net page?
Ahmed Bensaid at 24-Jun-13 10:44am
   
Yes you can ... you can use AJAX with javascript or with the jQuery library ... without being in an asp.net page ;)
Dustin Prevatt at 24-Jun-13 11:18am
   
I've been trying different examples I've seen online, but so far can't make it work could you give me an example of how you've done it. Please! :)

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Follow - Calling ASMX from jQuery[^] for a simple example.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 480
1 Maciej Los 330
2 Richard MacCutchan 225
3 BillWoodruff 185
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,759
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,269
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 24 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100