How to use Webservice?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalsingh
    New Member
    • Sep 2006
    • 218

    How to use Webservice?

    hai all,

    i am new to web service(c#), i just tried helloworld, woked Perfectly!.
    now i want to work in 3 different computers.
    for eg: A, B, and C.

    in computer A i have a simple demo.aspx page, i want to pass two parameters to web service in computer B (webTest.asmx) and in Computer C i have a sqlserver 2000 database in which i have to save the parameter passed.

    Plz help me to implement this concept.

    thanking you
    -Nirmal.
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Congratulations on getting hello world to work! Now you have the task of creating another. What have tried so far? If you don't have a solution, or part thereof, you don't have a problem.

    Originally posted by nirmalsingh
    hai all,

    i am new to web service(c#), i just tried helloworld, woked Perfectly!.
    now i want to work in 3 different computers.
    for eg: A, B, and C.

    in computer A i have a simple demo.aspx page, i want to pass two parameters to web service in computer B (webTest.asmx) and in Computer C i have a sqlserver 2000 database in which i have to save the parameter passed.

    Plz help me to implement this concept.

    thanking you
    -Nirmal.

    Comment

    • nirmalsingh
      New Member
      • Sep 2006
      • 218

      #3
      Thanx for ur reply,
      my Code for webservice
      [HTML]using System;
      using System.Web;
      using System.Web.Serv ices;
      using System.Web.Serv ices.Protocols;

      [WebService(Name space = "http://nirmalsingh.org/")]
      [WebServiceBindi ng(ConformsTo = WsiProfiles.Bas icProfile1_1)]
      public class Service : System.Web.Serv ices.WebService
      {
      public Service () {

      //Uncomment the following line if using designed components
      //InitializeCompo nent();
      }

      [WebMethod]
      public string RenderMessage(s tring firstName,strin g secondName) {
      try
      {
      return "Welcome" + firstName + " " + secondName + " !";
      }
      catch (Exception ex)
      {
      return ex.Message;
      }
      }

      }[/HTML]
      client side code
      [HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
      <html>
      <body>
      <form target="_blank" action='http://localhost:1274/WebSite1/Service.asmx/RenderMessage'
      method="POST">
      <table>
      <tr>
      <td>First Name:</td>
      <td><input type="text"
      size="30" name="firstName "></td>
      </tr>
      <tr>
      <td></td>
      <td align="right"></td>
      </tr>
      <tr>
      <td>Second Name:</td>
      <td><input type="text"
      size="30" name="secondNam e"></td>
      </tr>
      <tr>
      <td></td>
      <td align="right"> <input type="submit"
      value="Submit" class="button"> </td>
      </tr>
      </table>
      </form>
      </body>
      </html>
      [/HTML]

      and also i tried it in code behind as
      [HTML]WebService curWS = new WebService();

      Service a = new Service ();
      Response.Write( a.RenderMessage ('a','b'));[/HTML]
      i have use both of this is in same machine, now i want to take it to remote. that is accesing webservice from another machine. is this right way i am moving? how should i proceed it to next level? plz guide me.
      thanx in advance.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Have you considered creating a Web Application (ASP.NET application) which consumes your WebService...

        Your ASP.NET application would probably take care of the "Welcome SoAndSo..."

        Your WebService would be responsible for taking care of your business logic and returning this to your ASP.NET application.

        I don't see how you are going to make a simple HTML page consume a Web Service. That is the responsibility of the ASP.NET application...t he ASP.NET application would then generate your HTML and serve it to the web browser.

        -Frinny

        Comment

        Working...