Sharepoint COM works from Silverlight but not from WPF - wpf

I'm running into an interesting situation. I need to access a SharePoint site asset library from both a WPF application and an Silverlight application. My Silverlight application is working 100%, but my WPF application gets a (500) Internal Server Error back from the service.
Silverlight Code:
private void Button_Click(object sender, RoutedEventArgs e)
{
ClientContext clientContext = new ClientContext("http://myfullyQualifiedName.com");
clientContext.Load(clientContext.Web);
clientContext.ExecuteQueryAsync(onQuerySucceeded, onQueryFailed);
}
private void onQuerySucceeded(object sender, ClientRequestSucceededEventArgs args)
{
}
private void onQueryFailed(object sender, ClientRequestFailedEventArgs args)
{
}
WPF Code:
private void Button_Click(object sender, RoutedEventArgs e)
{
ClientContext clientContext = new ClientContext("http://myfullyqualifiedname.com/");
//clientContext.Credentials = new NetworkCredential("UserName", "Password", "Domain");
clientContext.Load(clientContext.Web);
clientContext.ExecuteQuery();
}
I have tried with and without specifying credentials, either way I get the Internal server error.
Both Silverlight and non Silverlight Sharepoint client DLL's that I use has is version 14.4762.1000.
Now if I change the URL to one of our other sites, the WPF Code works flawlessly. So I think it must be a SharePoint settings somewhere.

Solved !! Why WPF Authentication wouldn't work when Silverlight works. (WPF was trying to use Kerberos, Silverlight was using NTLM) - Simple fix:
ClientContext _clientContext = new ClientContext(sharePointSiteUrl);
Web _web = _clientContext.Web;
_clientContext.Load(_web, website => website.Title);
_clientContext.Load(_web.Webs);
CredentialCache cc = new CredentialCache();
cc.Add(new Uri(sharePointSiteUrl), "NTLM", CredentialCache.DefaultNetworkCredentials);
_clientContext.Credentials = cc;
_clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
_clientContext.ExecuteQuery();
ListCollection _listCollection = _web.Lists;

Related

AxInterop.ShockwaveFlashObjects missing in COM objects

I am trying to run SWF game in my WPF application. This game accepts some variables which should be constantly updated (about 100 times a second). I did some research and I know that basically there are 2 possibilities to run SWF in WPF:
Embed WebBrowser and pass path to the SWF file.
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// fixes warning about ActiveX security
string C_Drive_local = "file://127.0.0.1/c$/";
// path of the flash file, here its in C:\DemoContent\bounce.swf
Uri swfPath = new Uri( C_Drive_local + "DemoContent/bounce.swf");
// load it in the browser
MySWFBrowser.Source = swfPath;
}
Use WindowsFormsHost to host an AxShockwaveFlash control
private void FlashLoaded(object sender, RoutedEventArgs e)
{
WindowsFormsHost formHost = new WindowsFormsHost();
AxShockwaveFlash axShockwaveFlash = new AxShockwaveFlash();
formHost.Child = axShockwaveFlash;
mainGrid.Children.Add(formHost);
string flashPath = Environment.CurrentDirectory;
flashPath += #"\game.swf";
axShockwaveFlash.Movie = flashPath;
}
I would like to try with AxShockwaveFlash since it provides methods for setting variables but in my COM objects I can not see AxInterop.ShockwaveFlashObjects.dll
I tried to install several different versions of Flash Player but without success. I cannt find any information about it. How can I get AxInterop.ShockwaveFlashObjects.dll ? What should I install to have it?

Accessing Webservices from Silverlight - Security Issue

I am trying to get a simple WebClient call working from Silverlight to youtube. I lifted the code from the Microsoft Silverlight site.
Here is the code:
private void SearchTrack_Click(object sender, RoutedEventArgs e)
{
Uri serviceUri = new Uri("https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&q=sara+smile&key=AAAAAAAAAAAAAAA");
WebClient downloader = new WebClient();
downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);
downloader.OpenReadAsync(serviceUri);
}
void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
Stream responseStream = e.Result;
// Continue working with responseStream here...
}
}
The call fails with the following error:
[System.Security.SecurityException] = {System.Security.SecurityException ---> System.Security.SecurityException: Security error.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa.
If I just hit the URL from my browser the JSON is returned without an issue.
I am running the application from VS/Cassini so I don't think it is the FIle system problem identified at http://blogs.msdn.com/b/silverlightws/archive/2008/03/30/some-tips-on-cross-domain-calls.aspx.
Any help would be greatly appreciated.
Barry
Here it's said, that it's not possible so easy to interract with google apis from silverlight because of corssdomain access restrictions. You need to add some intermidiate WCF-service, through which Your SL-app will communicate with youtube api.

silverlight exit call a Web service

I want to send data to the server when you close the application
public App()
{
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
this.UnhandledException += this.Application_UnhandledException;
InitializeComponent();
}
private void Application_Exit(object sender, EventArgs e)
{
ClientReverse.UserExitGameAsync((Guid)Login);
}
Server:
public void UserExitGame(Guid UserGuid)
{
Games.Games.ExitUserGames(UserGuid);
}
but the server side is not satisfied.
It is already too late when you reach the ApplicationExit event.
I have seen Javascript that keeps on a webpage until confirmed (Stack Overflow does it a lot). You might want to modify a version of that Javascript that sends a message back to the Silverlight app before it allows page closing.
Calling Silverlight methods from JS is easy (you can simply expose SL methods to JS with the [Scriptable] attribute).

Silverlight Windows Phone 7: Load Images From URL

I got the code below that is trying to load an image from the web into an Image control, when I run it I get an error on the given line that no network access is allowed:
private void button1_Click(object sender, RoutedEventArgs e)
{
WebClient webClientImgDownloader = new WebClient();
webClientImgDownloader.OpenReadCompleted += new OpenReadCompletedEventHandler(webClientImgDownloader_OpenReadCompleted);
webClientImgDownloader.OpenReadAsync(new Uri("http://dilbert.com/dyn/str_strip/000000000/00000000/0000000/000000/80000/5000/100/85108/85108.strip.print.gif", UriKind.Absolute));
}
void webClientImgDownloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(e.Result); // ERROR HERE!
image1.Source = bitmap;
}
Silverlight for Windows Phone 7
Trying to download content with WebClient will require a client access policy file to be present on the source server. For images you can avoid this requirement by doing it like this:-
private void button1_Click(object sender, RoutedEventArgs e)
{
Uri uri = new Uri("http://dilbert.com/dyn/str_strip/000000000/00000000/0000000/000000/80000/5000/100/85108/85108.strip.print.gif", UriKind.Absolute)
image1.Source = new BitmapImage(uri);
}
I see you're retrieving the image from Dilbert.com does that site have a cross domain policy file?
Silverlight doesn't support GIF only JPG, so I wrote:
www.lenniedevilliers.net/displaygif.aspx?link=http://dilbert.com/dyn/str_strip/000000000/00000000/0000000/000000/80000/5000/100/85108/85108.strip.print.gif
the displaygif.aspx page convert the GIF into a JPG.
Can you give us the full exception stack trace? the error could be that your phone emulator does not have internet access, or it could be the image on the dilbert server that does not allow anonymous requests that did not originate from their site ... so guidance on a solution will differ :-)

Download a html file in Silverlight

I'm trying to use the WebClient class to download a html file from another website and present it as a text stream, But I'm getting a security error, what am I doing wrong, or is this another one of Silverlights security "Features"
[code]
namespace ImageScrape
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
WebClient cl = new WebClient();
cl.OpenReadCompleted += new OpenReadCompletedEventHandler(cl_OpenReadCompleted);
cl.OpenReadAsync(new Uri(#"http://www.google.co.uk/",UriKind.Absolute));
}
void cl_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
testTextBlock.Text = e.Result.ToString();
}
}
}
[/code]
EDIT
Thanks guys, I was really hoping I wouldn't have to create this as a WCF service as 1) I only know the basics and 2) The idea is that you can use this .xap without having to connect to a central server, mainly because for this I don't have a server that I could host a WCF service on.
Does anyone know a way to get around this, or anywhere that would host a WCF service for free?
I think there are security issues with going directly to another site from the silverlight client.
The best work around for this would be to move this code into a web service and then serve the content you require to client from there.

Resources