Un esempio di come chiamare un servizio WCF che implementa il protocollo REST in JSON tramite l'oggetto Webclient.

C#

string url = "http://sgart.sharepoint.local/_vti_bin/timesheet.svc/HD/CdcAndCompany";

using (System.Net.WebClient wc = new System.Net.WebClient())
{
  //imposto il corretto content-type
  wc.Headers.Add("Content-Type", "application/json; charset=utf-8");
  
  //imposto le credenziali per autenticarmi su SharePoint
  wc.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

  //eseguo la chiamata passando i parametri in POST
  string result = wc.UploadString(url, @"{""loginName"":""SGART\\user1"",""requestType"":""authorization""}");

  //stampo il risultato
 Console.WriteLine(result);
}
In SharePoint un servizio WCF che implementa il protocollo JSON deve avere il Factory impostato a Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory
Tags:
C#235 Esempi224 JSON31 SharePoint498 SharePoint 2010224 SharePoint 2013137 WCF18
Potrebbe interessarti anche: