H
hazz
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
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