Click here to Skip to main content
13,006,530 members (62,048 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 = "")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    public class Service1 : System.Web.Services.WebService
        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;
            SqlDataReader dr = cmd.ExecuteReader();

                return dr["id"].ToString();

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">
    <td>GET ID</td>
    <input class="frmInput" type="text" size="30" name="id">
    <td align="right">
     <input type="submit" id="submitButton" value="Submit" class="button">
<script language="javascript">

the soap message that appears is below.

<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="">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 18:09pm
Updated 24-Jun-13 4:34am
Mahesh Bailwal 23-Jun-13 4:56am
can you share your soap message.
Dustin Prevatt 24-Jun-13 10:33am
adding the soap message...
eng.amir.ebrahimi 23-Jun-13 6:07am
Read AJAX ...if you wanna call a webservice in your web application ...The best way is AJAX !
Dustin Prevatt 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 page?
Ahmed Bensaid 24-Jun-13 10:44am
Yes you can ... you can use AJAX with javascript or with the jQuery library ... without being in an page ;)
Dustin Prevatt 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
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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170628.1 | Last Updated 24 Jun 2013
Copyright © CodeProject, 1999-2017
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