Jump to content

Having problems accessing a method from web service (C#)

Shammikit

so im trying to access a web service from windows forms and im sure that the connection between the two are working properly as i can access the default method helloworld from my windows form and anything i put inside the hello world in the web service method i can access it from my winforms. however when i create a new method, for example a method called loadmessage inside the web service,build it and try to access it from my winforms i get the error saying theres no such definition called loadmessage in the webservice. i couldnt find a solution for this. the code i have tried is shown below

 

------------------------------------------------------webservice---------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebApplication1
{
    /// <summary>
    /// Summary description for WebService2
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WebService2 : System.Web.Services.WebService
    {
      
      [WebMethod]
        public string loadmessage()//loads the posts to datagrid view in home page 
        {
          string a ="from load message";
            return a;
        }
    }
}


---------------------------------------------------------winforms-----------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace testAPP
{
    public partial class Form1 : Form
    {
      webserver.WebService2 Class1 = new webserver.WebService2();
      
      private void button1_Click(object sender, EventArgs e)
        {
            string z; 
            z =  Class1.loadmessage(); 
            MessageBox.Show(z);
        }
            
    }
}

 

sk.PNG

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×