HI all,
I am trying to integrate CRM with sarepoint, I am following these links,
https://code.msdn.microsoft.com/SharePoint-Integration-c5f21604/view/Discussions#content
and
http://journeyintocrm.com/archives/182
This is the code I am tring..
public string GetRequestDigest()
{
string digest = String.Empty;
Uri url = new Uri(String.Format("{0}/{1}", SiteUrl, contextInfoQuery));
byte[] result = HttpHelper.SendODataJsonRequest(
url,
"POST", // Retrieving the Context Info needs a POST Method
new byte[0],
(HttpWebRequest)HttpWebRequest.Create(url),
SpoAuthUtility.Current // pass in the helper object that allows us to make authenticated calls to SPO rest services
);
// use the DataContractJsonSerializer instead of the JavascriptSerializer (system.web.extension.dll cannot be used in the sandbox)
MemoryStream stream = new MemoryStream(result);
stream.Position = 0;
DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(ContextInfo));
ContextInfo ci = (ContextInfo)json.ReadObject(stream);
/// ContextInfo ci = (ContextInfo)json.Deserialize(Encoding.UTF8.GetString(result, 0, result.Length), typeof(ContextInfo));
digest = (ci != null) ? ci.FormDigestValue : String.Empty;
return digest;
}
/// <summary>
/// Helper class to handle ContextInfo JSON Deserialisation
/// </summary>
class ContextInfo
{
public Dictionary<string, Dictionary<string, object>> d { get; set; }
public String FormDigestValue
{
get
{
string value = String.Empty;
try
{
if (d != null && d.FirstOrDefault().Value != null)
{
value = Convert.ToString(d.FirstOrDefault().Value["FormDigestValue"]);
}
}
catch { }
return value;
}
}
}
I am getting error in GetRequestDigest() Method, Error message says :
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Type 'SharepointUpload.SpoAuthUtility+ContextInfo' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
Detail: <OrganizationServiceFault xmlns="schemas.microsoft.com/.../Contracts" xmlns:i="www.w3.org/.../XMLSchema-instance">
<ActivityId>00000000-0000-0000-0000-000000000000</ActivityId>
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:a="schemas.datacontract.org/.../System.Collections.Generic">
<KeyValuePairOfstringanyType>
<a:key>CallStack</a:key>
<a:value i:type="b:string" xmlns:b="www.w3.org/.../XMLSchema"> at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String message, Type type)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.get_RootContract()
at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalIsStartObject(XmlReaderDelegator reader)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader)
at SharepointUpload.SpoAuthUtility.GetRequestDigest()
at SharepointUpload.UploadFile.Execute(IServiceProvider serviceProvider)
at PluginProfiler.Library.PluginAppDomainProxy.ExecuteCore(Stopwatch watch, ProfilerExecutionReport report, Object instance, Object executionParameter)
at PluginProfiler.Library.AppDomainProxy.Execute(ProfilerExecutionConfiguration configuration, ProfilerExecutionReport report)</a:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<Message>Type 'SharepointUpload.SpoAuthUtility+ContextInfo' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.</Message>
<Timestamp>2017-12-12T09:38:40.2094703Z</Timestamp>
<ExceptionSource i:nil="true" />
<InnerFault i:nil="true" />
<OriginalException i:nil="true" />
<TraceText i:nil="true" />
</OrganizationServiceFault>