I was developing an Windows Phone 7 application today. As you may know WP7 does not support authentication for NTLM. The only thing you can do (as I know, I am still open for new recommendations) is form based; in which you have to add login information to the request header.
The thing i was doing was using client object model. Actually I could not handle anything, I tried Authentication.asmx and try to get some cookie from there, but I was not able to authenticate myself (because the firm's form based settings were corrupted, and i guess they did not want to create this settings again, and continued with NTLM)
So I added references (Microsoft.Sharepoint.Client and *.Runtime) and created a ClientContext class as:
(ClientContext context = new ClientContext("urlhere"))
Added necessary credentials as:
context.Credentials =
new System.Net.NetworkCredential("username", "pass", "domain");
Fetch my data from a WebService that I created and installed to IIS (You have to create an Empty Asp.Net project, add a web service, build it, and Add an Application to your Site in IIS, show the directory of the ASP.NET project)
Everything was going perfect afterwards, I was able to get data but, sometimes I was seeing this error message:
"The underlying connection was closed: A connection that was expected to be kept alive was closed by the server."
So after a little research I figured it out, this error is caused by WebRequest, which does not close itself after ClientContext.ExecuteQuery() function.
So solution I found was adding this little magical line:
using(ClientContext context = new ClientContext("url"))
{
context.PendingRequest.RequestExecutor.WebRequest.KeepAlive = false
This will say the web request object that sends request; "dude, just chill down"
Yeah I know, it is nothing, but still, I am sure someone is going to need this while trying to get Lists from sharepoint with a WP7!
Hiç yorum yok:
Yorum Gönder