Search

ObjectDataSource/GridView & Web Service with Authentication by tedteng

Closed
as By Design Help for as By Design

4
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 118420
Opened: 10/19/2004 12:57:19 AM
Access Restriction: Public
0
Workaround(s)
1
User(s) can reproduce this bug
ObjectDataSource/GridView & Web Service with Authentication

I am testing Asp. Net 2.0 's the new controls of ObjectDataSource and GridView bound with a web service.

//defintion..Part I

    ListsService.Lists listsS;// ListsService is a List Web Service provide intranet Sharepoint site
    System.Xml.XmlNode xmlNode;
    GridView gView;
    ObjectDataSource oDS;
    XmlDataSource xmlDS;

//page_load..Part II

        listsS = new ListsService.Lists();
        listsS.Url = "http://intranet/_vti_bin/Lists.asmx";
        listsS.Credentials = System.Net.CredentialCache.DefaultCredentials;//this passes the credential to list servcie
        xmlNode = GetRecordsByMonth(System.DateTime.Today);
        xmlDS = new XmlDataSource();
        xmlDS.Data = xmlNode.OuterXml;
        xmlDS.ID = "xmlDS";
        this.form1.Controls.Add(xmlDS);

.....

//create a object data source control ...Part III

        oDS = new ObjectDataSource();
        oDS.TypeName = "ListsService.Lists";
        oDS.SelectMethod = "GetList";
        oDS.ID = "oDSID";

        Parameter pm = new Parameter();
        pm.Type = TypeCode.String;
        pm.Name = "listName"; pm.DefaultValue = "Events";
        //pm.Direction = ParameterDirection.ReturnValue;
        oDS.SelectParameters.Add(pm);
        this.form1.Controls.Add(oDS);

//create a grid view..Part IV

        gView = new GridView();
        gView.DataSourceID = oDS.ID; this.form1.Controls.Add(gView);

U c, in Part II, which is a traditional coing style, there I can pass the credential parameters via the Credential property but in part III and IV, i do not have a chance to set the authentication. there is no such a property to store the parameters. SO finnaly I got an error when running codes of Part III and IV:

The request failed with HTTP status 401: Unauthorized

It looks to me the read access did not get the authentication of the web service.
Details (expand)
Product Language
English
Version
Visual Web Dev 2005 Express Beta 1
Category
Web Project
Operating System
Windows Server 2003
Operating System Language
US English
Steps to Reproduce
It looks I do not get chance to pass the authentication when webserivce is bound to datagrid view. This bound is not through creating an instance of websrvice. The new feature of VS2005 seems to allow me to create a direct link between webservcie and datagrid. however, if without the authentication step like an instance does, it seems this bound is not authenticated.
Actual Results
The request failed with HTTP status 401: Unauthorized
Expected Results
The objectdatasource could enable user to integrate the authentication DIRECTLY without the traditonal creating instance way.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 10/22/2004 at 6:15 PM
Thanks for the feedback. You should be able to set this by handling the OnObjectCreating event of ObjectDataSource and setting your instance in code. For example:

    void ObjectDataSource1_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
    {
        listsS = new ListsService.Lists();
        listsS.Url = "http://intranet/_vti_bin/Lists.asmx";
        listsS.Credentials = System.Net.CredentialCache.DefaultCredentials; //this passes the credential to list service
        e.ObjectInstance = listsS;        
    }
Posted by tedteng on 10/24/2004 at 6:21 PM
Thanks for ur suggestiom. The code u recommend to me is ok. I have said in the intial suggestion. Ussing instance and passing the autenticatio are ok.

listsS = new ListsService.Lists();
listsS.Url = "http://intranet/_vti_bin/Lists.asmx";
listsS.Credentials = System.Net.CredentialCache.DefaultCredentials; //this passes the credential to list service
e.ObjectInstance = listsS;




MY problem is what i want to directly link the objectdatasource if WITHOUT creating such a instance.

//create a object data source control ...Part III

oDS = new ObjectDataSource();
oDS.TypeName = "ListsService.Lists";
oDS.SelectMethod = "GetList";
oDS.ID = "oDSID";

Parameter pm = new Parameter();
pm.Type = TypeCode.String;
pm.Name = "listName"; pm.DefaultValue = "Events";
//pm.Direction = ParameterDirection.ReturnValue;
oDS.SelectParameters.Add(pm);
this.form1.Controls.Add(oDS);

//create a grid view..Part IV

gView = new GridView();
gView.DataSourceID = oDS.ID; this.form1.Controls.Add(gView);


If i use above codes, it will return an error:

The request failed with HTTP status 401: Unauthorized
Posted by Microsoft on 10/25/2004 at 7:20 PM
Thanks for the suggestion. I understand your request, but the ObjectDataSource design requires you to create an instance in order to set custom instance properties, like authentication, on the object prior to the method calls. In a future release we are considering a WebServiceDataSource control that would likely have your authentication scenario covered in a declarative way.

The Web Platform and Tools Team