views:

8

answers:

0

In SL 4 app, it could need to access web services or pages on another remote site.

Suppose the Web app to host SL4 app is runing on IIS and use windows authentication, then the app need to access web services on another website which use same domain account from AD. How to pass the user credential when using WebClient to access the web service? I tried following code(based on the guide from http://timheuer.com/blog/archive/2009/11/18/whats-new-in-silverlight-4-complete-guide-new-features.aspx)

// NetworkCredential passing is available in ClientHttp networking stack
WebRequest.RegisterPrefix("http://", System.Net.Browser.WebRequestCreator.ClientHttp);
WebClient myService = new WebClient();

    myService.UseDefaultCredentials = false; // must be set to false if providing your own credentials
    myService.Credentials = new NetworkCredential("myname", "mypassword");
    myService.DownloadStringCompleted +=new DownloadStringCompletedEventHandler(myService_DownloadStringCompleted);
    myService.DownloadStringAsync(new Uri("http://mysite/alfresco/service/helloworld?name=myname"));

But I failed. I got security error message.