Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts

    trying to display info from web service

    hey all.
    I am not very familiar with .net, only been studying for a short amount of time.

    I am attempting to make a simple page that will display data from a SOAP/xml web service.

    I made my basic page with a literal control with an id of mydiv, and I am trying to populate the div with the string response from the example, but I dont knwo near enough to get it to work correctly.

    error intellisense si giving me is :
    the best overloaded method match for 'StringGet.GetPageAsString(System.Uri)' has some invalid arguments

    this is my code behind:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.IO;
    using System.Net;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
            mydiv.Text = StringGet.GetPageAsString("http://www.example.com");
        }
    }
    public class StringGet
    {
        public static string GetPageAsString(Uri address)
        {
            string result = "";
    
            // Create the web request  
            HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
    
            // Get response  
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                // Get the response stream  
                StreamReader reader = new StreamReader(response.GetResponseStream());
    
                // Read the whole contents and return as a string  
                result = reader.ReadToEnd();
            }
         
            return result;
        }
    }

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    no suggestions at all?

  • #3
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,928
    Thanks
    46
    Thanked 203 Times in 202 Posts
    your class asks for a uri and you are sending a string; you cannot implicitly convert it

    try something like
    Code:
    string google = @"http://www.google.com";
    Uri demo = new Uri(google);
    string  mydiv = StringGet.GetPageAsString(demo);
    should work. Also don't forget to close your stream reader when you are done

    Code:
    // Read the whole contents and return as a string  
    result = reader.ReadToEnd();
    reader.Close();

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #4
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,928
    Thanks
    46
    Thanked 203 Times in 202 Posts
    or even
    Code:
    mydiv.Text = StringGet.GetPageAsString(new uri(@"http://www.example.com"));
    might work

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #5
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Ill give it a shot ty


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •