locked
" Cannot call 'DeviceApplication1.localhost.Service1.HelloWorld()' because it is a web method."-exception occurs RRS feed

  • Question

  •  web service code:

    public class Service1 : System.Web.Services.WebService

    {

    [WebMethod]

    public string HelloWorld()

    {

    return "Hello World";

    }

    }


    mobile  code:

    private void button1_Click(object sender, EventArgs e)

    {

    localhost.Service1 service = new localhost.Service1();

    label1.Text= service.HelloWorld();

    }
    exception:
    service.HelloWorld() Cannot call 'DeviceApplication1.localhost.Service1.HelloWorld()' because it is a web method.


    how to resolve?

    Thursday, February 5, 2009 9:20 AM

Answers

  • First, you must add web reference to the device project, you can't call directly. Next, it’s a “localhost” issue. You see, localhost means "host, this application is running on", not your development PC. Since application is running on the device, localhost is device. Thus unless you're running web server with your web service hosted on the device itself that would not work.
    You need to use actual server URL instead, like PC name or IP.


    This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by bharathi_m Friday, February 6, 2009 5:28 AM
    Thursday, February 5, 2009 4:56 PM