473,769 Members | 2,372 Online
Bytes | Software Development & Data Engineering Community
+ 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.WebE xception] {"The request failed with HTTP status 401:
Unauthorized."}
when trying to execute
this.dataGridVi ew1.DataSource = ws.ReturnStuden tDS();

not sure if it is relevant but the web.config in the web service project has
<authenticati on mode="Windows"/>
Here is the webservice.
[WebService(Name space = "http://tempuri.org/")]
[WebServiceBindi ng(ConformsTo = WsiProfiles.Bas icProfile1_1)]
public class Service : System.Web.Serv ices.WebService
{
public Service () {

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

returnStudentDS .Service ws = new returnStudentDS .Service();
this.dataGridVi ew1.DataSource = ws.ReturnStuden tDS();
<-------------------- line where exception is thrown
}
catch (Exception e)

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

}

Thanks,
-hazz
Nov 17 '05 #1
2 7165
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******** *****@TK2MSFTNG P09.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.WebE xception] {"The request failed with HTTP status 401:
Unauthorized."}
when trying to execute
this.dataGridVi ew1.DataSource = ws.ReturnStuden tDS();

not sure if it is relevant but the web.config in the web service project has <authenticati on mode="Windows"/>
Here is the webservice.
[WebService(Name space = "http://tempuri.org/")]
[WebServiceBindi ng(ConformsTo = WsiProfiles.Bas icProfile1_1)]
public class Service : System.Web.Serv ices.WebService
{
public Service () {

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

returnStudentDS .Service ws = new returnStudentDS .Service(); this.dataGridVi ew1.DataSource = ws.ReturnStuden tDS();
<-------------------- line where exception is thrown
}
catch (Exception e)

{
Console.WriteLi ne("{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******** ******@TK2MSFTN GP14.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******** *****@TK2MSFTNG P09.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.WebE xception] {"The request failed with HTTP status 401:
Unauthorized."}
when trying to execute
this.dataGridVi ew1.DataSource = ws.ReturnStuden tDS();

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

has
<authenticati on mode="Windows"/>
Here is the webservice.
[WebService(Name space = "http://tempuri.org/")]
[WebServiceBindi ng(ConformsTo = WsiProfiles.Bas icProfile1_1)]
public class Service : System.Web.Serv ices.WebService
{
public Service () {

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

returnStudentDS .Service ws = new

returnStudentDS .Service();
this.dataGridVi ew1.DataSource = ws.ReturnStuden tDS();
<-------------------- line where exception is thrown
}
catch (Exception e)

{
Console.WriteLi ne("{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
3263
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 Unauthorized'); echo 'Text to send if user hits Cancel button'; exit; } else {
1
15104
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 virtual directory and will only be used internally on our network. The script works fine with the authentication set as "basic authentication" but this prompts the user for a login and password. I want it to be automated which I believe would...
0
1496
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 mode="On"> <error statusCode="404" redirect="http://localhost/ErrorPages/Error404.aspx"/> </customErrors>
2
1161
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
2199
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 debugger when I check the properties - 'domain', 'user name' and 'password' set in the ReportingService.Credentials; they are blank!!!
2
3129
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 scripts using a php script I get the error message Http 401: Unauthorised. This usually happens after a short time, when the webservices have not been used. I am connecting to the webservices using Http Post and cURL.
3
3161
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 if user hits Cancel button'; exit; } else {
11
8336
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 turn is called by another application). This all works fine in my development environment. Test environment: Windows Server 2003, ASP 6.0, .NET 2.0, Anonymous authentication is enabled. All components (web service, DLL, and calling application)...
10
9778
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 returned. So the username and password should be ok. I'm using this code: Merchant myMerch = new Merchant(); myMerch.merchantIdentifier=merchantId;
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9981
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7396
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3948
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3551
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.