473,511 Members | 15,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

localhost usage in web service


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.

Dec 6 '07 #1
20 6707
I believe localhost is the name that you give to the web reference when you
Add Reference. It could be anything

Jeff

"rkbnair" <rk*****@community.nospamwrote in message
news:97**********************************@microsof t.com...
>
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.

Dec 6 '07 #2
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/subscripti...ult.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/subscripti...t/default.aspx.

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

--------------------
>From: =?Utf-8?B?cmtibmFpcg==?= <rk*****@community.nospam>
Subject: localhost usage in web service
Date: Thu, 6 Dec 2007 14:24:01 -0800
>

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.

Dec 7 '07 #3

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
"Steven Cheng[MSFT]" wrote:
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/subscripti...ult.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/subscripti...t/default.aspx.

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

--------------------
From: =?Utf-8?B?cmtibmFpcg==?= <rk*****@community.nospam>
Subject: localhost usage in web service
Date: Thu, 6 Dec 2007 14:24:01 -0800


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.

Dec 7 '07 #4
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==?= <rk*****@community.nospam>
References: <97**********************************@microsoft.co m>
<Vk**************@TK2MSFTNGHUB02.phx.gbl>
>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
"Steven Cheng[MSFT]" wrote:
>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/subscripti...ult.aspx#notif
>ications.

Dec 10 '07 #5
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
"Steven Cheng[MSFT]" wrote:
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==?= <rk*****@community.nospam>
References: <97**********************************@microsoft.co m>
<Vk**************@TK2MSFTNGHUB02.phx.gbl>
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
"Steven Cheng[MSFT]" wrote:
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/subscripti...ult.aspx#notif
ications.


Dec 10 '07 #6
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.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:CA**********************************@microsof t.com...
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
"Steven Cheng[MSFT]" wrote:
>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==?= <rk*****@community.nospam>
References: <97**********************************@microsoft.co m>
<Vk**************@TK2MSFTNGHUB02.phx.gbl>
>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
"Steven Cheng[MSFT]" wrote:

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


Dec 10 '07 #7
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" wrote:
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.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:CA**********************************@microsof t.com...
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
"Steven Cheng[MSFT]" wrote:
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==?= <rk*****@community.nospam>
References: <97**********************************@microsoft.co m>
<Vk**************@TK2MSFTNGHUB02.phx.gbl>
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
"Steven Cheng[MSFT]" wrote:

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

Dec 10 '07 #8
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...


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================

"rkbnair" <rk*****@community.nospamwrote in message news:0B**********************************@microsof t.com...
>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" wrote:
>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.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:CA**********************************@microsof t.com...
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
"Steven Cheng[MSFT]" wrote:

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==?= <rk*****@community.nospam>
References: <97**********************************@microsoft.co m>
<Vk**************@TK2MSFTNGHUB02.phx.gbl>
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
"Steven Cheng[MSFT]" wrote:

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


Dec 10 '07 #9
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" wrote:
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...


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================

"rkbnair" <rk*****@community.nospamwrote in message news:0B**********************************@microsof t.com...
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" wrote:
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.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:CA**********************************@microsof t.com...
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
"Steven Cheng[MSFT]" wrote:

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==?= <rk*****@community.nospam>
References: <97**********************************@microsoft.co m>
<Vk**************@TK2MSFTNGHUB02.phx.gbl>
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
"Steven Cheng[MSFT]" wrote:

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



Dec 10 '07 #10
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.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:5E**********************************@microsof t.com...
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" wrote:
>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...


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================

"rkbnair" <rk*****@community.nospamwrote in message news:0B**********************************@microsof t.com...
>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" wrote:

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.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:CA**********************************@microsof t.com...
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
"Steven Cheng[MSFT]" wrote:

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==?= <rk*****@community.nospam>
References: <97**********************************@microsoft.co m>
<Vk**************@TK2MSFTNGHUB02.phx.gbl>
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
"Steven Cheng[MSFT]" wrote:

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




Dec 10 '07 #11
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" wrote:
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.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:5E**********************************@microsof t.com...
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" wrote:
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...


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================

"rkbnair" <rk*****@community.nospamwrote in message news:0B**********************************@microsof t.com...
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" wrote:

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.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:CA**********************************@microsof t.com...
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
"Steven Cheng[MSFT]" wrote:

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==?= <rk*****@community.nospam>
References: <97**********************************@microsoft.co m>
<Vk**************@TK2MSFTNGHUB02.phx.gbl>
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
"Steven Cheng[MSFT]" wrote:

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




Dec 10 '07 #12
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.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:FA**********************************@microsof t.com...
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" wrote:
>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.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:5E**********************************@microsof t.com...
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" wrote:

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...


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================

"rkbnair" <rk*****@community.nospamwrote in message news:0B**********************************@microsof t.com...
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" wrote:

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.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message
news:CA**********************************@microso ft.com...
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
"Steven Cheng[MSFT]" wrote:

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==?= <rk*****@community.nospam>
References: <97**********************************@microsoft.co m>
<Vk**************@TK2MSFTNGHUB02.phx.gbl>
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
"Steven Cheng[MSFT]" wrote:

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





Dec 10 '07 #13
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" wrote:
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.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:FA**********************************@microsof t.com...
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" wrote:
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.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:5E**********************************@microsof t.com...
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" wrote:

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...


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================

"rkbnair" <rk*****@community.nospamwrote in message news:0B**********************************@microsof t.com...
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" wrote:

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);
}
}
---------------
Dec 10 '07 #14
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

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:47**********************************@microsof t.com...
>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" wrote:
>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.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:FA**********************************@microsof t.com...
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" wrote:

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.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:5E**********************************@microsof t.com...
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" wrote:

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...


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================

"rkbnair" <rk*****@community.nospamwrote in message
news:0B**********************************@microso ft.com...
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" wrote:

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);
}
}
---------------

Dec 11 '07 #15
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);
}
}
---------------
Dec 11 '07 #16
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" wrote:
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

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:47**********************************@microsof t.com...
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" wrote:
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.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:FA**********************************@microsof t.com...
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" wrote:

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.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"rkbnair" <rk*****@community.nospamwrote in message news:5E**********************************@microsof t.com...
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" wrote:

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 :
Dec 11 '07 #17
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[MSFT]" wrote:
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);
}
}
---------------

Dec 11 '07 #18
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);
}

}
}
>>
Dec 12 '07 #19
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: st*****@online.microsoft.com (Steven Cheng[MSFT])
Organization: Microsoft
Date: Wed, 12 Dec 2007 03:01:51 GMT
Subject: Re: localhost usage in web service
>
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.
>> }
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
else
return Convert.ToSingle (A / B);
}

}
}
>>>

Dec 14 '07 #20
Hi rkbnair,

After some checking on the solution you send me, here are something I found
maybe the cause of the problem you met:

** Regardless of the service project, the client project which reference
and call the webservice is a ".NET 3.0+" project. Thus, that project
doesn't have "Add WebReference" function, but have "Add serviceReference".
Therefore, the proxy you generated is a WCF service client proxy.

** Event for WCF client proxy, you didn't type the proxy's namespace and
class name correctly. I've verified that the proxy class's
namespace+classname is as below:

"ServiceReference1.service1soap"
"ServiceReference2.service1soap"

rather than "localhost.xxxx", there is no "localhost" here.

If you're wantting to develop .NET 2.0 application and consume the
webservice, you should choose ".NET Framework 2.0" when you creating the
project in Visual Studio 2008. .NET 2.0 project in VS 2008 does provide
"Add WebReference" function like VS 2005 project.

Also, for client proxy namespace+classname, please click into the "Web
Reference" node in Solution Explorer so as to get the actual
value(actually, you can get intellisense support when you type the root
namespace of the certain webreference).

I'll also send you back a modified version of the project(in that one I
still remains your .NET 3.0 client project, but changed the client proxy
declaration to the correct namespace+classname).

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: st*****@online.microsoft.com (Steven Cheng[MSFT])
Organization: Microsoft
Date: Fri, 14 Dec 2007 10:21:21 GMT
Subject: Re: localhost usage in web service
>
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: st*****@online.microsoft.com (Steven Cheng[MSFT])
Organization: Microsoft
Date: Wed, 12 Dec 2007 03:01:51 GMT
Subject: Re: localhost usage in web service
>>
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.
>>
>>> }
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
else
return Convert.ToSingle (A / B);
}

}
}
>>>>


Dec 17 '07 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3674
by: Michael Adkins | last post by:
I have a new ASP project that I need to desperately test on my Windows 2000 machine before posing to my Hosting Company. I am having problems getting the ASP pages to run from LocalHost. I will...
7
5176
by: George Gre | last post by:
Hi, I wrote a c# programme that listens to incoming TCP requests and services them. This programme is meant to be running as long as the server its installed on is running. So we assume for...
8
15924
by: Greg Merideth | last post by:
I've written a basic windows service to provide some helper xml functions for my web methods and even thou the service is only about 1k lines long with 1 timer, its mem usage is 10m and its vm mem...
2
1612
by: Fish | last post by:
I have been researching the correct way to organize my solution so that it makes best use of VB.NET inherent ability to manage resources such as objects. My solution contains 2 projects and the...
5
2207
by: greg.merideth | last post by:
I'm working on a service for a project that is producing some bizarre behavior. In debug mode while the service is running, the memory usage of the service (watching with process explorer) goes...
5
20111
by: ljlevend2 | last post by:
Is there any way to create a local server during runtime? For example, if you add an existing Web Site to a Solution from within Visual Studio (by right clicking the solution in the Solution...
2
2446
by: jld | last post by:
Hi, I developed an asp.net based eCommerce Website for a client and it is hosted at discount asp. The site is quite interactive, queries a database a lot and uses ajax.asp.net to spice up...
3
2342
by: maciek kanski | last post by:
Hello I have running WCF service (config below) hosting in just console application - because I've used InstanceContextMode.Single and ConcurrencyMode.Multiple and no Throttling I expect that 10...
0
1642
by: BHollister | last post by:
Hi All, I have written a web service that works fine in development and fails when deployed to my localhost. The development solution is configured as: Business Object Project Service...
0
7144
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7427
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.