473,473 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

HTTP status 401: Unauthorized when accessing web service method via winform in same VS2005 solution.

I don't get it. I have a VS2005 solution with a web service project and a
windows project. The web service when tested on its own works fine. But when
I add it as a web reference and refer to it my windows form code behind I
receive the following;
[System.Net.WebException] {"The request failed with HTTP status 401:
Unauthorized."}
when trying to execute
this.dataGridView1.DataSource = ws.ReturnStudentDS();

not sure if it is relevant but the web.config in the web service project has
<authentication mode="Windows"/>
Here is the webservice.
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {

}
[WebMethod]
public DataSet ReturnStudentDS() {
SqlConnection myConnection = new
SqlConnection("server=(local);database=Smartdb ;Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from
Student", myConnection);
DataSet ds = new DataSet();
return ds;
}
}
Here is the winform accessing the webmethod.
public Form1()
{
InitializeComponent();
try
{

returnStudentDS.Service ws = new returnStudentDS.Service();
this.dataGridView1.DataSource = ws.ReturnStudentDS();
<-------------------- line where exception is thrown
}
catch (Exception e)

{
Console.WriteLine("{0} Exception caught.", e);

}

Thanks,
-hazz
Nov 17 '05 #1
2 7142
is the user executing the code authenticated?
It seems like it is not. You can try removing authentication and seeing if
you can hit the webservice.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"hazz" <hazz@sonic_net> wrote in message
news:ev*************@TK2MSFTNGP09.phx.gbl...
I don't get it. I have a VS2005 solution with a web service project and a
windows project. The web service when tested on its own works fine. But when I add it as a web reference and refer to it my windows form code behind I
receive the following;
[System.Net.WebException] {"The request failed with HTTP status 401:
Unauthorized."}
when trying to execute
this.dataGridView1.DataSource = ws.ReturnStudentDS();

not sure if it is relevant but the web.config in the web service project has <authentication mode="Windows"/>
Here is the webservice.
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {

}
[WebMethod]
public DataSet ReturnStudentDS() {
SqlConnection myConnection = new
SqlConnection("server=(local);database=Smartdb ;Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from
Student", myConnection);
DataSet ds = new DataSet();
return ds;
}
}
Here is the winform accessing the webmethod.
public Form1()
{
InitializeComponent();
try
{

returnStudentDS.Service ws = new returnStudentDS.Service(); this.dataGridView1.DataSource = ws.ReturnStudentDS();
<-------------------- line where exception is thrown
}
catch (Exception e)

{
Console.WriteLine("{0} Exception caught.", e);

}

Thanks,
-hazz

Nov 17 '05 #2
I am running it all on my local machine Alvin.
Stupid question on my part. What do you mean executing the code
authenticated. How do I remove authentication?
setting it to None in the web config? I tried that.

Thanks, -hazz

"Alvin Bruney - ASP.NET MVP" <www.lulu.com/owc> wrote in message
news:u9**************@TK2MSFTNGP14.phx.gbl...
is the user executing the code authenticated?
It seems like it is not. You can try removing authentication and seeing if
you can hit the webservice.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"hazz" <hazz@sonic_net> wrote in message
news:ev*************@TK2MSFTNGP09.phx.gbl...
I don't get it. I have a VS2005 solution with a web service project and a
windows project. The web service when tested on its own works fine. But

when
I add it as a web reference and refer to it my windows form code behind I
receive the following;
[System.Net.WebException] {"The request failed with HTTP status 401:
Unauthorized."}
when trying to execute
this.dataGridView1.DataSource = ws.ReturnStudentDS();

not sure if it is relevant but the web.config in the web service project

has
<authentication mode="Windows"/>
Here is the webservice.
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {

}
[WebMethod]
public DataSet ReturnStudentDS() {
SqlConnection myConnection = new
SqlConnection("server=(local);database=Smartdb ;Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from
Student", myConnection);
DataSet ds = new DataSet();
return ds;
}
}
Here is the winform accessing the webmethod.
public Form1()
{
InitializeComponent();
try
{

returnStudentDS.Service ws = new

returnStudentDS.Service();
this.dataGridView1.DataSource = ws.ReturnStudentDS();
<-------------------- line where exception is thrown
}
catch (Exception e)

{
Console.WriteLine("{0} Exception caught.", e);

}

Thanks,
-hazz


Nov 17 '05 #3

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

Similar topics

5
by: Sparkplug | last post by:
I have used the simple example of HTTP Authentication from the PHP website as follows: <?php if (!isset($_SERVER)) { header('WWW-Authenticate: Basic realm="My Realm"'); header('HTTP/1.0 401...
1
by: Newbie | last post by:
I have set up an ASP script (with some help from microsoft.public.inetserver.asp.general!) that grabs the windows username of the user and puts it into an Access database. It is setup on IIS5 as a...
0
by: Daniel Kopp | last post by:
Hi! I tried to implement custom error pages using the <customErrors> directive in a web.config file. It worked fine for "simple" errors like HTTP 404, like this example: <customErrors...
2
by: Sachin | last post by:
Scenario: Machine A: ASP.NET Web UI IIS 6.0 Windows Server 2003 Impersonation Account: domain\Acct1 Machine B: ASP.NET Web Service IIS 6.0
0
by: Shree | last post by:
While invoking the web service from client, I am setting the credentitals using the following code... ReportingService.Credentials = System.Net.CredentialCache.DefaultCredentials; But in...
2
by: Iain Adams | last post by:
I currently have a web service set that returns data. When I use these services through a browser, everything works fine and the resulting xml is displayed. However sometimes when I connect to the...
3
by: Reporter | last post by:
Here is an example from the PHP Manual <?php if ((!isset($_SERVER)) || (1==1)) { header('WWW-Authenticate: Basic realm="My Realm"'); header('HTTP/1.0 401 Unauthorized'); echo 'Text to send...
11
by: jjw92 | last post by:
I've been banging my head against the wall with this one for a couple days so I'm hoping someone has some ideas. I have a web service that I created that is called by a .NET class library (which in...
10
by: Anton | last post by:
Hi, when accessing a secured 3rd party webservice i'm getting a 401 HTTP Statuscode (unauthorized). When entering the url in a browser and entering the username and password manually, the wsdl is...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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

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