Please see my code as follows: It still gives error on the last line.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();
ConsoleApplication1.ServiceReference1.Service myMathService =
new ConsoleApplication1.ServiceReference1.Service();
}
}
}
--
test
:
If you copy-pasted the code from the KB,
in Program.cs ( the ConsoleApplication1 program ), include this :
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
localhost.Service myMathService = new localhost.Service();
Console.Write("2 + 4 = {0}", myMathService.Add(2, 4));
}
}
}
Notice that it uses "localhost.Service myMathService = new localhost.Service();",
instead of "localhost.Service1 myMathService = new localhost.Service1();"
That's because service.cs has this declaration :
public class Service : System.Web.Services.WebService
If you changed the class name to something else besides "Service",
change that line to whatever you changed the classname to.
i.e., if you changed the classname to "whatever", change the line :
localhost.Service myMathService = new localhost.Service();
to
localhost.whatever myMathService = new localhost.whatever();
localhost.xxxx refers to the name of the web service class.
I just tested that...and everything was fine.
Don't forget to give the ASP.NET account permission
to access the web service's virtual directory...
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/
======================================
I want to invoke a webservice from the console application.
Due to some reason, the following two lines are not recognized by the compiler
using System.Web.Services;
using System.Web.Services.Protocols;
--
test
:
re:
!> The type or namespace name 'Service' does not exist in the namespace
!> 'ConsoleApplication1.ServiceReference1' (are you missing an assembly reference?)
Are you attempting to call a Console Application as a Web Service ?
I just followed the instructions in the KB you referenced (
http://support.microsoft.com/kb/308359 )
and had no problems reproducing the expected behavior.
Here's the source code for both files...for you to test :
\App_Code\service.cs :
--------------------------------
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace =
http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public int Add(int a, int b)
{
return(a + b);
}
[WebMethod]
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
[WebMethod]
public System.Single Multiply(System.Single A, System.Single B)
{
return A * B;
}
[WebMethod]
public System.Single Divide(System.Single A, System.Single B)
{
if(B == 0)
return -1;
return Convert.ToSingle(A / B);
}
}
---------------
Service.asmx :
---------------------
<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="Service" %>
---000---
Now, if you call
http://localhost/AnyDirectory/service.asmx you should be able to invoke the Web Service.
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/
======================================
No luck with that as well.
I get the following error message:
The type or namespace name 'Service' does not exist in the namespace
'ConsoleApplication1.ServiceReference1' (are you missing an assembly
reference?)
--
test
:
Thanks for your reply rkbnair,
For the new problem you meet, it seems due to the following things:
"ConsoleApplication1.ServiceReference1" is the namespace of your
auto-generated proxy class, you need to include the full class name so as
to create the instance of the proxy. As far as I know, the autogenerated
proxy's service class(if no multi service in same namespace) is named
"Service". So the code should be look like below:
============
ConsoleApplication1.ServiceReference1.Service myMathService = new
ConsoleApplication1.ServiceReference1.Service();
=================
Please let me know if this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: =?Utf-8?B?cmtibmFpcg==?= <
[email protected]>
References: <
[email protected]>
<
[email protected]>
Subject: RE: localhost usage in web service
Date: Fri, 7 Dec 2007 08:44:04 -0800
I checked the name which is as given below.
ConsoleApplication1.ServiceReference1 myMathService = new
ConsoleApplication1.ServiceReference1();
Now the error is as follows:
ConsoleApplication1.ServiceReference1' is a 'namespace' but is used like a
'type'
test
:
Hi rkbnair,
As Jeff has mentioned, in the example "localhost" is just a namespace
which
is determined when you add the webservice reference into your project.
It
could be customized as any other value. For your case, have you ever
specify a different namespace for it? To verify this you can either:
1. open classview in your project to find the webservice proxy class and
see what's its namespace
2. find the webservice proxy class from the "WebReference" node in
solution
explorer and check it.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead