Search code examples
c#silverlightodataazure-devops

How to talk to TFSOData service from Silverlight 5 application


I'm trying to obtain information from an online TFS server. The endpoint address for the OData service is: https://tfsodata.visualstudio.com/DefaultCollection.

I try and authenticate with this service using basic authentication as per:

     _context = new TFSOData.TFSData(new Uri("https://tfsodata.visualstudio.com/DefaultCollection", UriKind.Absolute));

                _context.SendingRequest2 += (object sender, SendingRequest2EventArgs e) =>
                {

                    String creds = String.Format(CultureInfo.InvariantCulture, @"{0}\{1}:{2}", "mydomain", "myusername", "mypassword");
                    var bytes = Encoding.UTF8.GetBytes(creds);
                    var credstring = Convert.ToBase64String(bytes);
                    e.RequestMessage.SetHeader("Authorization", "Basic " + credstring);
                };

Unfortunately I always get an exception returned from the eventArgs of my LoadCompleted Callback when I try and run a query on the Odata service and the query I'm running comes back empty when I know it shouldn't be.

    {System.Security.SecurityException: Security error.}

Am I doing anything wrong security wise? I've tested my alternate credentials for this odata service in the browser and they work fine.

Just to reiterate, I'm doing this in a silverlight 5 project. I've had a similar method working in WPF before using e.requestheaders.add etc., but that's not available to me in Silverlight.

EDIT:

I've also noticed from using Fiddler that it's going to the clientaccesspolicy.xml file and then not continuing on to actually get the data I wanted from the service. Obviously this is the difference between the WPF app and the Silverlight app, however looking at the clientaccesspolicy.xml and crossdomain.xml files I can see that they are both allowing * and so I should be able to access what I want.


Solution

  • This was because the server was not setup to allow Cross Origin Resource Sharing.