Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. calling web service

calling web service

Scheduled Pinned Locked Moved C#
xmlhelpcsharpasp-netwcf
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ramkithepower
    wrote on last edited by
    #1

    I am newbie to webservices I am trying to learn about them, but got struck in the first place itself. Please help me out. My service.cs in the web service. --------------------------------

    using System;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;

    [WebService(Namespace = "http://localhost:1458/forumservices/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Service : System.Web.Services.WebService
    {
    public Service () {

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

    [WebMethod]
    public string welcome(string name)
    {
    return "Welcome " + name;
    }

    }

    now on a button click from another web page

    protected void Button1_Click(object sender, EventArgs e)
    {

    try
    {
    soapMessage =
    @"
    <?xml version=""1.0"" encoding=""utf-8""?>
    <soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">
    soap12:Body
    <welcome xmlns=""http://localhost:1458/forumservices/"">
    <name>Rajas</name>
    </welcome>
    </soap12:Body>
    </soap12:Envelope>";

    WebClient mClient = new WebClient();

    Response.Write(System.Text.Encoding.ASCII.GetString(mClient.UploadData("http://localhost:1458/forumservices/Service.asmx", "POST", System.Text.Encoding.ASCII.GetBytes(soapMessage))));
    }
    catch (System.Net.WebException ex)
    {
    if (ex.Response != null)
    {
    Stream strm = ex.Response.GetResponseStream();
    StreamReader sr = new StreamReader(strm);
    Response.Write(sr.ReadToEnd());
    }
    else
    {
    Response.Write(ex.InnerException.ToString());
    }
    }

    }

    The compilation is fine, but i keep getting some errors as below "The remote server returned an error: (500) Internal Server Error." Please help me out I had posted the exam same thing in ASP.NET forum, but got no replies.

    Jack Sparrow -------------------------------------- Defeat is not the worst of failures. Not to have tried is the true failure.

    P 1 Reply Last reply
    0
    • R Ramkithepower

      I am newbie to webservices I am trying to learn about them, but got struck in the first place itself. Please help me out. My service.cs in the web service. --------------------------------

      using System;
      using System.Web;
      using System.Web.Services;
      using System.Web.Services.Protocols;

      [WebService(Namespace = "http://localhost:1458/forumservices/")]
      [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
      public class Service : System.Web.Services.WebService
      {
      public Service () {

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

      [WebMethod]
      public string welcome(string name)
      {
      return "Welcome " + name;
      }

      }

      now on a button click from another web page

      protected void Button1_Click(object sender, EventArgs e)
      {

      try
      {
      soapMessage =
      @"
      <?xml version=""1.0"" encoding=""utf-8""?>
      <soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">
      soap12:Body
      <welcome xmlns=""http://localhost:1458/forumservices/"">
      <name>Rajas</name>
      </welcome>
      </soap12:Body>
      </soap12:Envelope>";

      WebClient mClient = new WebClient();

      Response.Write(System.Text.Encoding.ASCII.GetString(mClient.UploadData("http://localhost:1458/forumservices/Service.asmx", "POST", System.Text.Encoding.ASCII.GetBytes(soapMessage))));
      }
      catch (System.Net.WebException ex)
      {
      if (ex.Response != null)
      {
      Stream strm = ex.Response.GetResponseStream();
      StreamReader sr = new StreamReader(strm);
      Response.Write(sr.ReadToEnd());
      }
      else
      {
      Response.Write(ex.InnerException.ToString());
      }
      }

      }

      The compilation is fine, but i keep getting some errors as below "The remote server returned an error: (500) Internal Server Error." Please help me out I had posted the exam same thing in ASP.NET forum, but got no replies.

      Jack Sparrow -------------------------------------- Defeat is not the worst of failures. Not to have tried is the true failure.

      P Offline
      P Offline
      Pranay Rana
      wrote on last edited by
      #2

      According to me to consume webservice in you application you need to add webreferace of webservice in you application than to call web service you need to create objct of that and than you can call webservice. Check on following link which give you idea about how to consume website. http://it.toolbox.com/wiki/index.php/Calling_a_web_service_from_Asp.net[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups