localhost usage in web service

R

rkbnair

I was executing the steps given in http://suppor.microsoft.com/kb/308359 for
testing a sample web service application. However, the following line gives a
compilation error:

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

localhost is not recognized by the compiler.
 
J

Jeff Dillon

I believe localhost is the name that you give to the web reference when you
Add Reference. It could be anything

Jeff
 
S

Steven Cheng[MSFT]

Hi rkbnair,

As Jeff has mentioned, in the example "localhost" is just a namespace which
is determined when you add the webservice reference into your project. It
could be customized as any other value. For your case, have you ever
specify a different namespace for it? To verify this you can either:

1. open classview in your project to find the webservice proxy class and
see what's its namespace

2. find the webservice proxy class from the "WebReference" node in solution
explorer and check it.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================


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



--------------------
 
R

rkbnair

I checked the name which is as given below.

ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();

Now the error is as follows:

ConsoleApplication1.ServiceReference1' is a 'namespace' but is used like a
'type'


test
 
S

Steven Cheng[MSFT]

Thanks for your reply rkbnair,

For the new problem you meet, it seems due to the following things:

"ConsoleApplication1.ServiceReference1" is the namespace of your
auto-generated proxy class, you need to include the full class name so as
to create the instance of the proxy. As far as I know, the autogenerated
proxy's service class(if no multi service in same namespace) is named
"Service". So the code should be look like below:

============
ConsoleApplication1.ServiceReference1.Service myMathService = new
ConsoleApplication1.ServiceReference1.Service();
=================

Please let me know if this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


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


--------------------
From: =?Utf-8?B?cmtibmFpcg==?= <[email protected]>
References: <[email protected]>
Subject: RE: localhost usage in web service
Date: Fri, 7 Dec 2007 08:44:04 -0800
 
R

rkbnair

No luck with that as well.
I get the following error message:
The type or namespace name 'Service' does not exist in the namespace
'ConsoleApplication1.ServiceReference1' (are you missing an assembly
reference?)
 
J

Juan T. Llibre

re:
!> The type or namespace name 'Service' does not exist in the namespace
!> 'ConsoleApplication1.ServiceReference1' (are you missing an assembly reference?)

Are you attempting to call a Console Application as a Web Service ?

I just followed the instructions in the KB you referenced ( http://support.microsoft.com/kb/308359 )
and had no problems reproducing the expected behavior.

Here's the source code for both files...for you to test :

\App_Code\service.cs :
--------------------------------
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = http://tempuri.org/)]
[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 int Add(int a, int b)
{
return(a + b);
}
[WebMethod]
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
[WebMethod]
public System.Single Multiply(System.Single A, System.Single B)
{
return A * B;
}
[WebMethod]
public System.Single Divide(System.Single A, System.Single B)
{
if(B == 0)
return -1;
return Convert.ToSingle(A / B);
}
}
---------------
Service.asmx :
---------------------
<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="Service" %>

---000---

Now, if you call http://localhost/AnyDirectory/service.asmx you should be able to invoke the Web Service.
 
R

rkbnair

I want to invoke a webservice from the console application.
Due to some reason, the following two lines are not recognized by the compiler

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


--
test


Juan T. Llibre said:
re:
!> The type or namespace name 'Service' does not exist in the namespace
!> 'ConsoleApplication1.ServiceReference1' (are you missing an assembly reference?)

Are you attempting to call a Console Application as a Web Service ?

I just followed the instructions in the KB you referenced ( http://support.microsoft.com/kb/308359 )
and had no problems reproducing the expected behavior.

Here's the source code for both files...for you to test :

\App_Code\service.cs :
--------------------------------
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = http://tempuri.org/)]
[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 int Add(int a, int b)
{
return(a + b);
}
[WebMethod]
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
[WebMethod]
public System.Single Multiply(System.Single A, System.Single B)
{
return A * B;
}
[WebMethod]
public System.Single Divide(System.Single A, System.Single B)
{
if(B == 0)
return -1;
return Convert.ToSingle(A / B);
}
}
---------------
Service.asmx :
---------------------
<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="Service" %>

---000---

Now, if you call http://localhost/AnyDirectory/service.asmx you should be able to invoke the Web Service.











rkbnair said:
No luck with that as well.
I get the following error message:
The type or namespace name 'Service' does not exist in the namespace
'ConsoleApplication1.ServiceReference1' (are you missing an assembly
reference?)
 
J

Juan T. Llibre

If you copy-pasted the code from the KB,
in Program.cs ( the ConsoleApplication1 program ), include this :

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
localhost.Service myMathService = new localhost.Service();
Console.Write("2 + 4 = {0}", myMathService.Add(2, 4));
}
}
}

Notice that it uses "localhost.Service myMathService = new localhost.Service();",
instead of "localhost.Service1 myMathService = new localhost.Service1();"

That's because service.cs has this declaration :

public class Service : System.Web.Services.WebService

If you changed the class name to something else besides "Service",
change that line to whatever you changed the classname to.

i.e., if you changed the classname to "whatever", change the line :
localhost.Service myMathService = new localhost.Service();

to

localhost.whatever myMathService = new localhost.whatever();

localhost.xxxx refers to the name of the web service class.

I just tested that...and everything was fine.

Don't forget to give the ASP.NET account permission
to access the web service's virtual directory...






rkbnair said:
I want to invoke a webservice from the console application.
Due to some reason, the following two lines are not recognized by the compiler

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


--
test


Juan T. Llibre said:
re:
!> The type or namespace name 'Service' does not exist in the namespace
!> 'ConsoleApplication1.ServiceReference1' (are you missing an assembly reference?)

Are you attempting to call a Console Application as a Web Service ?

I just followed the instructions in the KB you referenced ( http://support.microsoft.com/kb/308359 )
and had no problems reproducing the expected behavior.

Here's the source code for both files...for you to test :

\App_Code\service.cs :
--------------------------------
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = http://tempuri.org/)]
[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 int Add(int a, int b)
{
return(a + b);
}
[WebMethod]
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
[WebMethod]
public System.Single Multiply(System.Single A, System.Single B)
{
return A * B;
}
[WebMethod]
public System.Single Divide(System.Single A, System.Single B)
{
if(B == 0)
return -1;
return Convert.ToSingle(A / B);
}
}
---------------
Service.asmx :
---------------------
<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="Service" %>

---000---

Now, if you call http://localhost/AnyDirectory/service.asmx you should be able to invoke the Web Service.











rkbnair said:
No luck with that as well.
I get the following error message:
The type or namespace name 'Service' does not exist in the namespace
'ConsoleApplication1.ServiceReference1' (are you missing an assembly
reference?)

--
test


:

Thanks for your reply rkbnair,

For the new problem you meet, it seems due to the following things:

"ConsoleApplication1.ServiceReference1" is the namespace of your
auto-generated proxy class, you need to include the full class name so as
to create the instance of the proxy. As far as I know, the autogenerated
proxy's service class(if no multi service in same namespace) is named
"Service". So the code should be look like below:

============
ConsoleApplication1.ServiceReference1.Service myMathService = new
ConsoleApplication1.ServiceReference1.Service();
=================

Please let me know if this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


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


--------------------
From: =?Utf-8?B?cmtibmFpcg==?= <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: RE: localhost usage in web service
Date: Fri, 7 Dec 2007 08:44:04 -0800



I checked the name which is as given below.

ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();

Now the error is as follows:

ConsoleApplication1.ServiceReference1' is a 'namespace' but is used like a
'type'


test


:

Hi rkbnair,

As Jeff has mentioned, in the example "localhost" is just a namespace
which
is determined when you add the webservice reference into your project.
It
could be customized as any other value. For your case, have you ever
specify a different namespace for it? To verify this you can either:

1. open classview in your project to find the webservice proxy class and
see what's its namespace

2. find the webservice proxy class from the "WebReference" node in
solution
explorer and check it.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
 
R

rkbnair

Please see my code as follows: It still gives error on the last line.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;


namespace ConsoleApplication1
{
class Program
{

static void Main(string[] args)
{
//ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();
ConsoleApplication1.ServiceReference1.Service myMathService =
new ConsoleApplication1.ServiceReference1.Service();

}
}
}


--
test


Juan T. Llibre said:
If you copy-pasted the code from the KB,
in Program.cs ( the ConsoleApplication1 program ), include this :

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
localhost.Service myMathService = new localhost.Service();
Console.Write("2 + 4 = {0}", myMathService.Add(2, 4));
}
}
}

Notice that it uses "localhost.Service myMathService = new localhost.Service();",
instead of "localhost.Service1 myMathService = new localhost.Service1();"

That's because service.cs has this declaration :

public class Service : System.Web.Services.WebService

If you changed the class name to something else besides "Service",
change that line to whatever you changed the classname to.

i.e., if you changed the classname to "whatever", change the line :
localhost.Service myMathService = new localhost.Service();

to

localhost.whatever myMathService = new localhost.whatever();

localhost.xxxx refers to the name of the web service class.

I just tested that...and everything was fine.

Don't forget to give the ASP.NET account permission
to access the web service's virtual directory...






rkbnair said:
I want to invoke a webservice from the console application.
Due to some reason, the following two lines are not recognized by the compiler

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


--
test


Juan T. Llibre said:
re:
!> The type or namespace name 'Service' does not exist in the namespace
!> 'ConsoleApplication1.ServiceReference1' (are you missing an assembly reference?)

Are you attempting to call a Console Application as a Web Service ?

I just followed the instructions in the KB you referenced ( http://support.microsoft.com/kb/308359 )
and had no problems reproducing the expected behavior.

Here's the source code for both files...for you to test :

\App_Code\service.cs :
--------------------------------
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = http://tempuri.org/)]
[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 int Add(int a, int b)
{
return(a + b);
}
[WebMethod]
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
[WebMethod]
public System.Single Multiply(System.Single A, System.Single B)
{
return A * B;
}
[WebMethod]
public System.Single Divide(System.Single A, System.Single B)
{
if(B == 0)
return -1;
return Convert.ToSingle(A / B);
}
}
---------------
Service.asmx :
---------------------
<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="Service" %>

---000---

Now, if you call http://localhost/AnyDirectory/service.asmx you should be able to invoke the Web Service.











No luck with that as well.
I get the following error message:
The type or namespace name 'Service' does not exist in the namespace
'ConsoleApplication1.ServiceReference1' (are you missing an assembly
reference?)

--
test


:

Thanks for your reply rkbnair,

For the new problem you meet, it seems due to the following things:

"ConsoleApplication1.ServiceReference1" is the namespace of your
auto-generated proxy class, you need to include the full class name so as
to create the instance of the proxy. As far as I know, the autogenerated
proxy's service class(if no multi service in same namespace) is named
"Service". So the code should be look like below:

============
ConsoleApplication1.ServiceReference1.Service myMathService = new
ConsoleApplication1.ServiceReference1.Service();
=================

Please let me know if this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


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


--------------------
From: =?Utf-8?B?cmtibmFpcg==?= <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: RE: localhost usage in web service
Date: Fri, 7 Dec 2007 08:44:04 -0800



I checked the name which is as given below.

ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();

Now the error is as follows:

ConsoleApplication1.ServiceReference1' is a 'namespace' but is used like a
'type'


test


:

Hi rkbnair,

As Jeff has mentioned, in the example "localhost" is just a namespace
which
is determined when you add the webservice reference into your project.
It
could be customized as any other value. For your case, have you ever
specify a different namespace for it? To verify this you can either:

1. open classview in your project to find the webservice proxy class and
see what's its namespace

2. find the webservice proxy class from the "WebReference" node in
solution
explorer and check it.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
 
J

Juan T. Llibre

re:
!> ConsoleApplication1.ServiceReference1.Service myMathService = new ConsoleApplication1.ServiceReference1.Service();

Questions :

1. Is your web service class named "ServiceReference1.Service" ?

If not, change that line to

localhost.YourWebServiceClassName myMathService = new localhost.YourWebServiceClassName();

You *must* name localhost.whatever the same name as your Web Service class.

Also, did you add a web reference to your service in the ConsoleApplication program ?
If not, you must add the reference.

Again : I tested this ...and it reproduced fine.






rkbnair said:
Please see my code as follows: It still gives error on the last line.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;


namespace ConsoleApplication1
{
class Program
{

static void Main(string[] args)
{
//ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();
ConsoleApplication1.ServiceReference1.Service myMathService =
new ConsoleApplication1.ServiceReference1.Service();

}
}
}


--
test


Juan T. Llibre said:
If you copy-pasted the code from the KB,
in Program.cs ( the ConsoleApplication1 program ), include this :

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
localhost.Service myMathService = new localhost.Service();
Console.Write("2 + 4 = {0}", myMathService.Add(2, 4));
}
}
}

Notice that it uses "localhost.Service myMathService = new localhost.Service();",
instead of "localhost.Service1 myMathService = new localhost.Service1();"

That's because service.cs has this declaration :

public class Service : System.Web.Services.WebService

If you changed the class name to something else besides "Service",
change that line to whatever you changed the classname to.

i.e., if you changed the classname to "whatever", change the line :
localhost.Service myMathService = new localhost.Service();

to

localhost.whatever myMathService = new localhost.whatever();

localhost.xxxx refers to the name of the web service class.

I just tested that...and everything was fine.

Don't forget to give the ASP.NET account permission
to access the web service's virtual directory...






rkbnair said:
I want to invoke a webservice from the console application.
Due to some reason, the following two lines are not recognized by the compiler

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


--
test


:

re:
!> The type or namespace name 'Service' does not exist in the namespace
!> 'ConsoleApplication1.ServiceReference1' (are you missing an assembly reference?)

Are you attempting to call a Console Application as a Web Service ?

I just followed the instructions in the KB you referenced ( http://support.microsoft.com/kb/308359 )
and had no problems reproducing the expected behavior.

Here's the source code for both files...for you to test :

\App_Code\service.cs :
--------------------------------
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = http://tempuri.org/)]
[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 int Add(int a, int b)
{
return(a + b);
}
[WebMethod]
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
[WebMethod]
public System.Single Multiply(System.Single A, System.Single B)
{
return A * B;
}
[WebMethod]
public System.Single Divide(System.Single A, System.Single B)
{
if(B == 0)
return -1;
return Convert.ToSingle(A / B);
}
}
---------------
Service.asmx :
---------------------
<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="Service" %>

---000---

Now, if you call http://localhost/AnyDirectory/service.asmx you should be able to invoke the Web Service.











No luck with that as well.
I get the following error message:
The type or namespace name 'Service' does not exist in the namespace
'ConsoleApplication1.ServiceReference1' (are you missing an assembly
reference?)

--
test


:

Thanks for your reply rkbnair,

For the new problem you meet, it seems due to the following things:

"ConsoleApplication1.ServiceReference1" is the namespace of your
auto-generated proxy class, you need to include the full class name so as
to create the instance of the proxy. As far as I know, the autogenerated
proxy's service class(if no multi service in same namespace) is named
"Service". So the code should be look like below:

============
ConsoleApplication1.ServiceReference1.Service myMathService = new
ConsoleApplication1.ServiceReference1.Service();
=================

Please let me know if this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


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


--------------------
From: =?Utf-8?B?cmtibmFpcg==?= <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: RE: localhost usage in web service
Date: Fri, 7 Dec 2007 08:44:04 -0800



I checked the name which is as given below.

ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();

Now the error is as follows:

ConsoleApplication1.ServiceReference1' is a 'namespace' but is used like a
'type'


test


:

Hi rkbnair,

As Jeff has mentioned, in the example "localhost" is just a namespace
which
is determined when you add the webservice reference into your project.
It
could be customized as any other value. For your case, have you ever
specify a different namespace for it? To verify this you can either:

1. open classview in your project to find the webservice proxy class and
see what's its namespace

2. find the webservice proxy class from the "WebReference" node in
solution
explorer and check it.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
 
R

rkbnair

Here is the code in the service file: BTW, localhost is not recognized by the
compiler.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace MathService
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[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 Service1 : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
public int Add(int a, int b)
{
return (a + b);
}
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
public System.Single Multiply(System.Single A, System.Single B)
{
return (A * B);
}
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
else
return Convert.ToSingle (A / B);
}

}
}


--
test


Juan T. Llibre said:
re:
!> ConsoleApplication1.ServiceReference1.Service myMathService = new ConsoleApplication1.ServiceReference1.Service();

Questions :

1. Is your web service class named "ServiceReference1.Service" ?

If not, change that line to

localhost.YourWebServiceClassName myMathService = new localhost.YourWebServiceClassName();

You *must* name localhost.whatever the same name as your Web Service class.

Also, did you add a web reference to your service in the ConsoleApplication program ?
If not, you must add the reference.

Again : I tested this ...and it reproduced fine.






rkbnair said:
Please see my code as follows: It still gives error on the last line.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;


namespace ConsoleApplication1
{
class Program
{

static void Main(string[] args)
{
//ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();
ConsoleApplication1.ServiceReference1.Service myMathService =
new ConsoleApplication1.ServiceReference1.Service();

}
}
}


--
test


Juan T. Llibre said:
If you copy-pasted the code from the KB,
in Program.cs ( the ConsoleApplication1 program ), include this :

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
localhost.Service myMathService = new localhost.Service();
Console.Write("2 + 4 = {0}", myMathService.Add(2, 4));
}
}
}

Notice that it uses "localhost.Service myMathService = new localhost.Service();",
instead of "localhost.Service1 myMathService = new localhost.Service1();"

That's because service.cs has this declaration :

public class Service : System.Web.Services.WebService

If you changed the class name to something else besides "Service",
change that line to whatever you changed the classname to.

i.e., if you changed the classname to "whatever", change the line :
localhost.Service myMathService = new localhost.Service();

to

localhost.whatever myMathService = new localhost.whatever();

localhost.xxxx refers to the name of the web service class.

I just tested that...and everything was fine.

Don't forget to give the ASP.NET account permission
to access the web service's virtual directory...






I want to invoke a webservice from the console application.
Due to some reason, the following two lines are not recognized by the compiler

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


--
test


:

re:
!> The type or namespace name 'Service' does not exist in the namespace
!> 'ConsoleApplication1.ServiceReference1' (are you missing an assembly reference?)

Are you attempting to call a Console Application as a Web Service ?

I just followed the instructions in the KB you referenced ( http://support.microsoft.com/kb/308359 )
and had no problems reproducing the expected behavior.

Here's the source code for both files...for you to test :

\App_Code\service.cs :
--------------------------------
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = http://tempuri.org/)]
[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 int Add(int a, int b)
{
return(a + b);
}
[WebMethod]
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
[WebMethod]
public System.Single Multiply(System.Single A, System.Single B)
{
return A * B;
}
[WebMethod]
public System.Single Divide(System.Single A, System.Single B)
{
if(B == 0)
return -1;
return Convert.ToSingle(A / B);
}
}
---------------
Service.asmx :
---------------------
<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="Service" %>

---000---

Now, if you call http://localhost/AnyDirectory/service.asmx you should be able to invoke the Web Service.











No luck with that as well.
I get the following error message:
The type or namespace name 'Service' does not exist in the namespace
'ConsoleApplication1.ServiceReference1' (are you missing an assembly
reference?)

--
test


:

Thanks for your reply rkbnair,

For the new problem you meet, it seems due to the following things:

"ConsoleApplication1.ServiceReference1" is the namespace of your
auto-generated proxy class, you need to include the full class name so as
to create the instance of the proxy. As far as I know, the autogenerated
proxy's service class(if no multi service in same namespace) is named
"Service". So the code should be look like below:

============
ConsoleApplication1.ServiceReference1.Service myMathService = new
ConsoleApplication1.ServiceReference1.Service();
=================

Please let me know if this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


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


--------------------
From: =?Utf-8?B?cmtibmFpcg==?= <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: RE: localhost usage in web service
Date: Fri, 7 Dec 2007 08:44:04 -0800



I checked the name which is as given below.

ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();

Now the error is as follows:

ConsoleApplication1.ServiceReference1' is a 'namespace' but is used like a
'type'


test


:

Hi rkbnair,

As Jeff has mentioned, in the example "localhost" is just a namespace
which
is determined when you add the webservice reference into your project.
It
could be customized as any other value. For your case, have you ever
specify a different namespace for it? To verify this you can either:

1. open classview in your project to find the webservice proxy class and
see what's its namespace

2. find the webservice proxy class from the "WebReference" node in
solution
explorer and check it.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
 
J

Juan T. Llibre

re:
!> public class Service1 : System.Web.Services.WebService

According to that source, your call should be :

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

....IF your web reference points to "localhost".

BUT, you missed transcribing a most important line of code: the class instantiation.

After


public class Service1 : System.Web.Services.WebService

You should have this line :

{
public Service1 ()
{

In other words, you are not instantiating your class.

Here's the whole context :
------------------------------------

[WebService(Namespace = http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service1 : System.Web.Services.WebService
{
public Service1 () {
//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public int Add(int a, int b)
///...etc.

re:
!> BTW, localhost is not recognized by the compiler

"localhost" is the name of the server where you're calling your service from.

If you have not pointed your web reference to "localhost", the name won't get recognized.

If you have created a virtual directory for the web service :

a. On the Project menu, click Add Web Reference.

b. In the Add Web Reference dialog box, type the URL for the Web service in the Address text box and press ENTER.
If you set the local computer to host the Web service, the URL is http://localhost/MathService/MathService.asmx.
c. Click Add Reference.





rkbnair said:
Here is the code in the service file: BTW, localhost is not recognized by the
compiler.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace MathService
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[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 Service1 : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
public int Add(int a, int b)
{
return (a + b);
}
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
public System.Single Multiply(System.Single A, System.Single B)
{
return (A * B);
}
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
else
return Convert.ToSingle (A / B);
}

}
}


--
test


Juan T. Llibre said:
re:
!> ConsoleApplication1.ServiceReference1.Service myMathService = new
ConsoleApplication1.ServiceReference1.Service();

Questions :

1. Is your web service class named "ServiceReference1.Service" ?

If not, change that line to

localhost.YourWebServiceClassName myMathService = new localhost.YourWebServiceClassName();

You *must* name localhost.whatever the same name as your Web Service class.

Also, did you add a web reference to your service in the ConsoleApplication program ?
If not, you must add the reference.

Again : I tested this ...and it reproduced fine.






rkbnair said:
Please see my code as follows: It still gives error on the last line.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;


namespace ConsoleApplication1
{
class Program
{

static void Main(string[] args)
{
//ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();
ConsoleApplication1.ServiceReference1.Service myMathService =
new ConsoleApplication1.ServiceReference1.Service();

}
}
}


--
test


:

If you copy-pasted the code from the KB,
in Program.cs ( the ConsoleApplication1 program ), include this :

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
localhost.Service myMathService = new localhost.Service();
Console.Write("2 + 4 = {0}", myMathService.Add(2, 4));
}
}
}

Notice that it uses "localhost.Service myMathService = new localhost.Service();",
instead of "localhost.Service1 myMathService = new localhost.Service1();"

That's because service.cs has this declaration :

public class Service : System.Web.Services.WebService

If you changed the class name to something else besides "Service",
change that line to whatever you changed the classname to.

i.e., if you changed the classname to "whatever", change the line :
localhost.Service myMathService = new localhost.Service();

to

localhost.whatever myMathService = new localhost.whatever();

localhost.xxxx refers to the name of the web service class.

I just tested that...and everything was fine.

Don't forget to give the ASP.NET account permission
to access the web service's virtual directory...






I want to invoke a webservice from the console application.
Due to some reason, the following two lines are not recognized by the compiler

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


--
test


:

re:
!> The type or namespace name 'Service' does not exist in the namespace
!> 'ConsoleApplication1.ServiceReference1' (are you missing an assembly reference?)

Are you attempting to call a Console Application as a Web Service ?

I just followed the instructions in the KB you referenced ( http://support.microsoft.com/kb/308359 )
and had no problems reproducing the expected behavior.

Here's the source code for both files...for you to test :

\App_Code\service.cs :
--------------------------------
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = http://tempuri.org/)]
[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 int Add(int a, int b)
{
return(a + b);
}
[WebMethod]
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
[WebMethod]
public System.Single Multiply(System.Single A, System.Single B)
{
return A * B;
}
[WebMethod]
public System.Single Divide(System.Single A, System.Single B)
{
if(B == 0)
return -1;
return Convert.ToSingle(A / B);
}
}
---------------
Service.asmx :
---------------------
<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="Service" %>

---000---

Now, if you call http://localhost/AnyDirectory/service.asmx you should be able to invoke the Web Service.











No luck with that as well.
I get the following error message:
The type or namespace name 'Service' does not exist in the namespace
'ConsoleApplication1.ServiceReference1' (are you missing an assembly
reference?)

--
test


:

Thanks for your reply rkbnair,

For the new problem you meet, it seems due to the following things:

"ConsoleApplication1.ServiceReference1" is the namespace of your
auto-generated proxy class, you need to include the full class name so as
to create the instance of the proxy. As far as I know, the autogenerated
proxy's service class(if no multi service in same namespace) is named
"Service". So the code should be look like below:

============
ConsoleApplication1.ServiceReference1.Service myMathService = new
ConsoleApplication1.ServiceReference1.Service();
=================

Please let me know if this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


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


--------------------
From: =?Utf-8?B?cmtibmFpcg==?= <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: RE: localhost usage in web service
Date: Fri, 7 Dec 2007 08:44:04 -0800



I checked the name which is as given below.

ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();

Now the error is as follows:

ConsoleApplication1.ServiceReference1' is a 'namespace' but is used like a
'type'


test


:

Hi rkbnair,

As Jeff has mentioned, in the example "localhost" is just a namespace
which
is determined when you add the webservice reference into your project.
It
could be customized as any other value. For your case, have you ever
specify a different namespace for it? To verify this you can either:

1. open classview in your project to find the webservice proxy class and
see what's its namespace

2. find the webservice proxy class from the "WebReference" node in
solution
explorer and check it.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
 
R

rkbnair

I made that change. Here is the new code: Still localhost is not recognized
by the compiler

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace MathService
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]


public class Service1 : System.Web.Services.WebService
{
public Service1 ()
{
}

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
public int Add(int a, int b)
{
return (a + b);
}
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
public System.Single Multiply(System.Single A, System.Single B)
{
return (A * B);
}
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
else
return Convert.ToSingle (A / B);
}

}
}


--
test


Juan T. Llibre said:
re:
!> public class Service1 : System.Web.Services.WebService

According to that source, your call should be :

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

....IF your web reference points to "localhost".

BUT, you missed transcribing a most important line of code: the class instantiation.

After


public class Service1 : System.Web.Services.WebService

You should have this line :

{
public Service1 ()
{

In other words, you are not instantiating your class.

Here's the whole context :
------------------------------------

[WebService(Namespace = http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service1 : System.Web.Services.WebService
{
public Service1 () {
//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public int Add(int a, int b)
///...etc.

re:
!> BTW, localhost is not recognized by the compiler

"localhost" is the name of the server where you're calling your service from.

If you have not pointed your web reference to "localhost", the name won't get recognized.

If you have created a virtual directory for the web service :

a. On the Project menu, click Add Web Reference.

b. In the Add Web Reference dialog box, type the URL for the Web service in the Address text box and press ENTER.
If you set the local computer to host the Web service, the URL is http://localhost/MathService/MathService.asmx.
c. Click Add Reference.





rkbnair said:
Here is the code in the service file: BTW, localhost is not recognized by the
compiler.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace MathService
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[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 Service1 : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
public int Add(int a, int b)
{
return (a + b);
}
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
public System.Single Multiply(System.Single A, System.Single B)
{
return (A * B);
}
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
else
return Convert.ToSingle (A / B);
}

}
}


--
test


Juan T. Llibre said:
re:
!> ConsoleApplication1.ServiceReference1.Service myMathService = new
ConsoleApplication1.ServiceReference1.Service();

Questions :

1. Is your web service class named "ServiceReference1.Service" ?

If not, change that line to

localhost.YourWebServiceClassName myMathService = new localhost.YourWebServiceClassName();

You *must* name localhost.whatever the same name as your Web Service class.

Also, did you add a web reference to your service in the ConsoleApplication program ?
If not, you must add the reference.

Again : I tested this ...and it reproduced fine.






Please see my code as follows: It still gives error on the last line.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;


namespace ConsoleApplication1
{
class Program
{

static void Main(string[] args)
{
//ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();
ConsoleApplication1.ServiceReference1.Service myMathService =
new ConsoleApplication1.ServiceReference1.Service();

}
}
}


--
test


:

If you copy-pasted the code from the KB,
in Program.cs ( the ConsoleApplication1 program ), include this :

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
localhost.Service myMathService = new localhost.Service();
Console.Write("2 + 4 = {0}", myMathService.Add(2, 4));
}
}
}

Notice that it uses "localhost.Service myMathService = new localhost.Service();",
instead of "localhost.Service1 myMathService = new localhost.Service1();"

That's because service.cs has this declaration :

public class Service : System.Web.Services.WebService

If you changed the class name to something else besides "Service",
change that line to whatever you changed the classname to.

i.e., if you changed the classname to "whatever", change the line :
localhost.Service myMathService = new localhost.Service();

to

localhost.whatever myMathService = new localhost.whatever();

localhost.xxxx refers to the name of the web service class.

I just tested that...and everything was fine.

Don't forget to give the ASP.NET account permission
to access the web service's virtual directory...






I want to invoke a webservice from the console application.
Due to some reason, the following two lines are not recognized by the compiler

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


--
test


:

re:
!> The type or namespace name 'Service' does not exist in the namespace
!> 'ConsoleApplication1.ServiceReference1' (are you missing an assembly reference?)

Are you attempting to call a Console Application as a Web Service ?

I just followed the instructions in the KB you referenced ( http://support.microsoft.com/kb/308359 )
and had no problems reproducing the expected behavior.

Here's the source code for both files...for you to test :

\App_Code\service.cs :
--------------------------------
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = http://tempuri.org/)]
[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 int Add(int a, int b)
{
return(a + b);
}
[WebMethod]
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
[WebMethod]
public System.Single Multiply(System.Single A, System.Single B)
{
return A * B;
}
[WebMethod]
public System.Single Divide(System.Single A, System.Single B)
{
if(B == 0)
return -1;
return Convert.ToSingle(A / B);
}
}
---------------
 
J

Juan T. Llibre

re:
!>Still localhost is not recognized by the compiler

"localhost" is the name of the server where you're calling your service from.

If you have not pointed your web reference to "localhost", the name won't get recognized.

If you have created a virtual directory named MathService for the web service :

a. On the Console Application Project menu, click Add Web Reference.

b. In the Add Web Reference dialog box, type the URL for the Web service in the Address text box and press ENTER.
If you set the local computer to host the Web service, the URL is http://localhost/MathService/MathService.asmx.
c. Click Add Reference.

After that, you'll have to identify the account which has permissions to access the resource.

Did you add the Web Reference to the Console Application project ?

If you did, you should have a Web Reference named "localhost",
and that Web Reference's URL syhould be : http://localhost/MathService/Service.asmx






rkbnair said:
I made that change. Here is the new code: Still localhost is not recognized
by the compiler

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace MathService
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]


public class Service1 : System.Web.Services.WebService
{
public Service1 ()
{
}

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
public int Add(int a, int b)
{
return (a + b);
}
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
public System.Single Multiply(System.Single A, System.Single B)
{
return (A * B);
}
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
else
return Convert.ToSingle (A / B);
}

}
}


--
test


Juan T. Llibre said:
re:
!> public class Service1 : System.Web.Services.WebService

According to that source, your call should be :

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

....IF your web reference points to "localhost".

BUT, you missed transcribing a most important line of code: the class instantiation.

After


public class Service1 : System.Web.Services.WebService

You should have this line :

{
public Service1 ()
{

In other words, you are not instantiating your class.

Here's the whole context :
------------------------------------

[WebService(Namespace = http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service1 : System.Web.Services.WebService
{
public Service1 () {
//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public int Add(int a, int b)
///...etc.

re:
!> BTW, localhost is not recognized by the compiler

"localhost" is the name of the server where you're calling your service from.

If you have not pointed your web reference to "localhost", the name won't get recognized.

If you have created a virtual directory for the web service :

a. On the Project menu, click Add Web Reference.

b. In the Add Web Reference dialog box, type the URL for the Web service in the Address text box and press ENTER.
If you set the local computer to host the Web service, the URL is http://localhost/MathService/MathService.asmx.
c. Click Add Reference.





rkbnair said:
Here is the code in the service file: BTW, localhost is not recognized by the
compiler.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace MathService
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[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 Service1 : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
public int Add(int a, int b)
{
return (a + b);
}
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
public System.Single Multiply(System.Single A, System.Single B)
{
return (A * B);
}
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
else
return Convert.ToSingle (A / B);
}

}
}


--
test


:

re:
!> ConsoleApplication1.ServiceReference1.Service myMathService = new
ConsoleApplication1.ServiceReference1.Service();

Questions :

1. Is your web service class named "ServiceReference1.Service" ?

If not, change that line to

localhost.YourWebServiceClassName myMathService = new localhost.YourWebServiceClassName();

You *must* name localhost.whatever the same name as your Web Service class.

Also, did you add a web reference to your service in the ConsoleApplication program ?
If not, you must add the reference.

Again : I tested this ...and it reproduced fine.






Please see my code as follows: It still gives error on the last line.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;


namespace ConsoleApplication1
{
class Program
{

static void Main(string[] args)
{
//ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();
ConsoleApplication1.ServiceReference1.Service myMathService =
new ConsoleApplication1.ServiceReference1.Service();

}
}
}


--
test


:

If you copy-pasted the code from the KB,
in Program.cs ( the ConsoleApplication1 program ), include this :

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
localhost.Service myMathService = new localhost.Service();
Console.Write("2 + 4 = {0}", myMathService.Add(2, 4));
}
}
}

Notice that it uses "localhost.Service myMathService = new localhost.Service();",
instead of "localhost.Service1 myMathService = new localhost.Service1();"

That's because service.cs has this declaration :

public class Service : System.Web.Services.WebService

If you changed the class name to something else besides "Service",
change that line to whatever you changed the classname to.

i.e., if you changed the classname to "whatever", change the line :
localhost.Service myMathService = new localhost.Service();

to

localhost.whatever myMathService = new localhost.whatever();

localhost.xxxx refers to the name of the web service class.

I just tested that...and everything was fine.

Don't forget to give the ASP.NET account permission
to access the web service's virtual directory...






I want to invoke a webservice from the console application.
Due to some reason, the following two lines are not recognized by the compiler

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


--
test


:

re:
!> The type or namespace name 'Service' does not exist in the namespace
!> 'ConsoleApplication1.ServiceReference1' (are you missing an assembly reference?)

Are you attempting to call a Console Application as a Web Service ?

I just followed the instructions in the KB you referenced ( http://support.microsoft.com/kb/308359 )
and had no problems reproducing the expected behavior.

Here's the source code for both files...for you to test :

\App_Code\service.cs :
--------------------------------
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = http://tempuri.org/)]
[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 int Add(int a, int b)
{
return(a + b);
}
[WebMethod]
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
[WebMethod]
public System.Single Multiply(System.Single A, System.Single B)
{
return A * B;
}
[WebMethod]
public System.Single Divide(System.Single A, System.Single B)
{
if(B == 0)
return -1;
return Convert.ToSingle(A / B);
}
}
---------------
 
S

Steven Cheng[MSFT]

Hi rkbnair,

I think there must have something we misunderstand with eachother here. To
make it easy, would you try creating a simplified solution which contains
two very simple project, one console app and one webservice app and the
console app call the webservice app. And that can repro the behavior, I may
help take a look at the test sln. How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


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


--------------------
Subject: Re: localhost usage in web service
Date: Mon, 10 Dec 2007 14:21:02 -0800
I made that change. Here is the new code: Still localhost is not recognized
by the compiler

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace MathService
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]


public class Service1 : System.Web.Services.WebService
{
public Service1 ()
{
}

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
public int Add(int a, int b)
{
return (a + b);
}
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
public System.Single Multiply(System.Single A, System.Single B)
{
return (A * B);
}
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
else
return Convert.ToSingle (A / B);
}

}
}


->> >> >> >> \App_Code\service.cs :
--------------------------------
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = http://tempuri.org/)]
[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 int Add(int a, int b)
{
return(a + b);
}
[WebMethod]
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
[WebMethod]
public System.Single Multiply(System.Single A, System.Single B)
{
return A * B;
}
[WebMethod]
public System.Single Divide(System.Single A, System.Single B)
{
if(B == 0)
return -1;
return Convert.ToSingle(A / B);
}
}
---------------
 
R

rkbnair

The web reference is this:
http://localhost:4470/MathService.asmx

Still the localhost is not shown in the intellisense popup window.
--
test


Juan T. Llibre said:
re:
!>Still localhost is not recognized by the compiler

"localhost" is the name of the server where you're calling your service from.

If you have not pointed your web reference to "localhost", the name won't get recognized.

If you have created a virtual directory named MathService for the web service :

a. On the Console Application Project menu, click Add Web Reference.

b. In the Add Web Reference dialog box, type the URL for the Web service in the Address text box and press ENTER.
If you set the local computer to host the Web service, the URL is http://localhost/MathService/MathService.asmx.
c. Click Add Reference.

After that, you'll have to identify the account which has permissions to access the resource.

Did you add the Web Reference to the Console Application project ?

If you did, you should have a Web Reference named "localhost",
and that Web Reference's URL syhould be : http://localhost/MathService/Service.asmx






rkbnair said:
I made that change. Here is the new code: Still localhost is not recognized
by the compiler

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace MathService
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]


public class Service1 : System.Web.Services.WebService
{
public Service1 ()
{
}

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
public int Add(int a, int b)
{
return (a + b);
}
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
public System.Single Multiply(System.Single A, System.Single B)
{
return (A * B);
}
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
else
return Convert.ToSingle (A / B);
}

}
}


--
test


Juan T. Llibre said:
re:
!> public class Service1 : System.Web.Services.WebService

According to that source, your call should be :

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

....IF your web reference points to "localhost".

BUT, you missed transcribing a most important line of code: the class instantiation.

After


public class Service1 : System.Web.Services.WebService

You should have this line :

{
public Service1 ()
{

In other words, you are not instantiating your class.

Here's the whole context :
------------------------------------

[WebService(Namespace = http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service1 : System.Web.Services.WebService
{
public Service1 () {
//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public int Add(int a, int b)
///...etc.

re:
!> BTW, localhost is not recognized by the compiler

"localhost" is the name of the server where you're calling your service from.

If you have not pointed your web reference to "localhost", the name won't get recognized.

If you have created a virtual directory for the web service :

a. On the Project menu, click Add Web Reference.

b. In the Add Web Reference dialog box, type the URL for the Web service in the Address text box and press ENTER.
If you set the local computer to host the Web service, the URL is http://localhost/MathService/MathService.asmx.
c. Click Add Reference.





Here is the code in the service file: BTW, localhost is not recognized by the
compiler.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace MathService
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[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 Service1 : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
public int Add(int a, int b)
{
return (a + b);
}
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
public System.Single Multiply(System.Single A, System.Single B)
{
return (A * B);
}
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
else
return Convert.ToSingle (A / B);
}

}
}


--
test


:

re:
!> ConsoleApplication1.ServiceReference1.Service myMathService = new
ConsoleApplication1.ServiceReference1.Service();

Questions :

1. Is your web service class named "ServiceReference1.Service" ?

If not, change that line to

localhost.YourWebServiceClassName myMathService = new localhost.YourWebServiceClassName();

You *must* name localhost.whatever the same name as your Web Service class.

Also, did you add a web reference to your service in the ConsoleApplication program ?
If not, you must add the reference.

Again : I tested this ...and it reproduced fine.






Please see my code as follows: It still gives error on the last line.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;


namespace ConsoleApplication1
{
class Program
{

static void Main(string[] args)
{
//ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();
ConsoleApplication1.ServiceReference1.Service myMathService =
new ConsoleApplication1.ServiceReference1.Service();

}
}
}


--
test


:

If you copy-pasted the code from the KB,
in Program.cs ( the ConsoleApplication1 program ), include this :

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
localhost.Service myMathService = new localhost.Service();
Console.Write("2 + 4 = {0}", myMathService.Add(2, 4));
}
}
}

Notice that it uses "localhost.Service myMathService = new localhost.Service();",
instead of "localhost.Service1 myMathService = new localhost.Service1();"

That's because service.cs has this declaration :
 
R

rkbnair

OK, I did that already.

Please find the code in both the web service and the console application:

CONSOLE APPLICATION:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;


namespace ConsoleApplication1
{
class Program
{

static void Main(string[] args)
{
//ConsoleApplication1.ServiceReference1.Service myMathService =
new ConsoleApplication1.ServiceReference1.Service();
localhost.Service1 myMathService = new localhost.Service1();

}
}
}


WEB SERVICE:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace MathService
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]

public class Service1 : System.Web.Services.WebService
{
public Service1 ()
{
}

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
public int Add(int a, int b)
{
return (a + b);
}
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
public System.Single Multiply(System.Single A, System.Single B)
{
return (A * B);
}
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
else
return Convert.ToSingle (A / B);
}

}
}


Thanks.
--
test


Steven Cheng said:
Hi rkbnair,

I think there must have something we misunderstand with eachother here. To
make it easy, would you try creating a simplified solution which contains
two very simple project, one console app and one webservice app and the
console app call the webservice app. And that can repro the behavior, I may
help take a look at the test sln. How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


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


--------------------
Subject: Re: localhost usage in web service
Date: Mon, 10 Dec 2007 14:21:02 -0800
I made that change. Here is the new code: Still localhost is not recognized
by the compiler

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace MathService
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]


public class Service1 : System.Web.Services.WebService
{
public Service1 ()
{
}

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
public int Add(int a, int b)
{
return (a + b);
}
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
public System.Single Multiply(System.Single A, System.Single B)
{
return (A * B);
}
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
else
return Convert.ToSingle (A / B);
}

}
}


->> >> >> >> \App_Code\service.cs :
--------------------------------
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = http://tempuri.org/)]
[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 int Add(int a, int b)
{
return(a + b);
}
[WebMethod]
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
[WebMethod]
public System.Single Multiply(System.Single A, System.Single B)
{
return A * B;
}
[WebMethod]
public System.Single Divide(System.Single A, System.Single B)
{
if(B == 0)
return -1;
return Convert.ToSingle(A / B);
}
}
---------------
 
S

Steven Cheng[MSFT]

Hi Rkbnair,

Would you send me the complete package? You can reach me at "stcheng"
+"@microsoft.com".

In addition to the code you provided, what I need much is the autogenerated
webservice proxy's code (normally it is a file named "Reference.cs"). The
namespace and class name there determines how you should declare and create
them in your main client code.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


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


--------------------
Thread-Topic: localhost usage in web service
thread-index: Acg8C9ZRvhwDfo42R3iSIBFC5jFSVA==
X-WBNR-Posting-Host: 208.46.106.5
Subject: Re: localhost usage in web service
Date: Tue, 11 Dec 2007 07:38:11 -0800
OK, I did that already.

Please find the code in both the web service and the console application:

CONSOLE APPLICATION:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;


namespace ConsoleApplication1
{
class Program
{

static void Main(string[] args)
{
//ConsoleApplication1.ServiceReference1.Service myMathService
=
new ConsoleApplication1.ServiceReference1.Service();
localhost.Service1 myMathService = new localhost.Service1();

}
}
}


WEB SERVICE:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace MathService
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]

public class Service1 : System.Web.Services.WebService
{
public Service1 ()
{
}

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
public int Add(int a, int b)
{
return (a + b);
}
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
public System.Single Multiply(System.Single A, System.Single B)
{
return (A * B);
}
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
else
return Convert.ToSingle (A / B);
}

}
}
 
S

Steven Cheng[MSFT]

Hi rkbnair,

I've got your project via email. I'll take a look and let you know what I
find.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


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

--------------------
From: (e-mail address removed) (Steven Cheng[MSFT])
Organization: Microsoft
Date: Wed, 12 Dec 2007 03:01:51 GMT
Subject: Re: localhost usage in web service
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,775
Messages
2,569,601
Members
45,182
Latest member
alexanderrm

Latest Threads

Top