By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,251 Members | 2,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,251 IT Pros & Developers. It's quick & easy.

localhost usage in web service

P: n/a

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
Share this Question
Share on Google+
20 Replies


P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.