SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jun 2006
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I get my web service working?

    HI Folks,

    Can someone please tell me how I can get my web service working.

    I'd like to display the results from this on my website.

    Thankyou

    When I browse to the page I get:


    Compiler Error Message: CS1518: Expected class, delegate, enum, interface, or struct

    Source Error:

    Line 1: <%@ WebService Language="C#" Class="GetNHSChoicesNewsArticlesList" %>
    Line 2: public string GetNHSChoicesNewsArticlesList(string userName, string password, string topic, int maxItems)
    Line 3: {
    Line 4: string strNewsArticlesListNewsML = String.Empty;

    My code is below:

    Code:
    <%@ WebService Language="C#" Class="GetNHSChoicesNewsArticlesList" %> 
    public string GetNHSChoicesNewsArticlesList(string userName, string password, string topic, int maxItems)
    {
        string strNewsArticlesListNewsML = String.Empty;
    
        // Create a web request object to access the web service
        // and add parameters to the web service in the query string
        HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create("http://www.nhs.uk/NHSCWS/News/NewsArticlesList.aspx?user=" + userName + "&pwd=" + password + "&topic=" + topic + "&max=" + maxItems.ToString());
    
        // Retrieve the response of the web service copy it in a string
        // with the help of stream reader
        HttpWebResponse webServiceResponse = (HttpWebResponse)myWebRequest.GetResponse();
        Stream streamResponse = webServiceResponse.GetResponseStream();
        StreamReader reader = new StreamReader(streamResponse,  Encoding.UTF8);
        strNewsArticlesListNewsML = reader.ReadToEnd();
    
        // Clean up
        reader.Close();
        webServiceResponse.Close();
        streamResponse.Close();
    
        // Return the news articles list NewsML retrieved
        // from the web service
        return strNewsArticlesListNewsML;
    }

  2. #2
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello,
    i 'm not sure this is what u want , try this
    right click your web project , Add New, Category Web, Add a WebServices.
    and below is the code example

    namespace ANameSpace
    {
    /// <summary>
    /// Summary description for AClassName
    /// </summary>
    ///
    [WebService(Namespace = "ANameSpace")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class AClassName : System.Web.Services.WebService
    {
    [WebMethod]
    public string GetNHSChoicesNewsArticlesList(string userName, string password, string topic, int maxItems)
    {
    string strNewsArticlesListNewsML = String.Empty;

    // Create a web request object to access the web service
    // and add parameters to the web service in the query string
    HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create("http://www.nhs.uk/NHSCWS/News/NewsArticlesList.aspx?user=" + userName + "&pwd=" + password + "&topic=" + topic + "&max=" + maxItems.ToString());

    // Retrieve the response of the web service copy it in a string
    // with the help of stream reader
    HttpWebResponse webServiceResponse = (HttpWebResponse)myWebRequest.GetResponse();
    Stream streamResponse = webServiceResponse.GetResponseStream();
    StreamReader reader = new StreamReader(streamResponse, Encoding.UTF8);
    strNewsArticlesListNewsML = reader.ReadToEnd();

    // Clean up
    reader.Close();
    webServiceResponse.Close();
    streamResponse.Close();

    // Return the news articles list NewsML retrieved
    // from the web service
    return strNewsArticlesListNewsML;
    }

    }
    }

    hope this help ^^


Bookmarks

Posting Permissions

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