locked
oData using Basic authentication RRS feed

  • Question

  • I am trying to access LightSwitch oData using Basic authentication but continue to have issues.

    var serviceCreds = new NetworkCredential("username", "password");
                var cache = new CredentialCache();
                var serviceUri = new Uri("https://hub.website.com/ApplicationData.svc/");
                cache.Add(serviceUri, "Basic", serviceCreds);
                
                var odataService = new ApplicationData(new Uri("https://hub.website.com/ApplicationData.svc/"));
                odataService.Credentials = cache;
     
    var localitmItems = odataService.mkgKeywords;
    

    The error message is:

    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
       at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
       at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
    

    Any suggestions would be greatly appreciated!

    Sincerely,

    Bill

    Tuesday, July 17, 2012 12:29 AM

Answers

  • When connecting from a console app, the following will work:

    ServiceReference1.ApplicationData ctx = new ServiceReference1.ApplicationData(new Uri(@"http://localhost/Application3/ApplicationData.svc"));
                var customers = ctx.Customers;
                ctx.Credentials = new NetworkCredential("test", "test");
                foreach (var item in customers)
                {
                    Console.WriteLine(item.LastName);
                }
    
                //adding a new customer
    
                Customer c = new Customer { LastName = "xyz", FirstName = "abc" };
                ctx.AddToCustomers(c);
                ctx.SaveChanges();
    
                Console.Read();


    paul van bladel

    Tuesday, July 17, 2012 7:30 AM