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