• Decrease Text SizeIncrease Text Size

Retrieve a Centralpoint document using a custom WCF service.

Posted Date: 5/3/2023
    Printer Friendly Version   Email A Friend   Add This   Increase Text Size   Decrease Text Size
1. In this example, we will demonstrate how you can retrieve a Centralpoint document using a WCF service.
Contact your production manager or sales representative to get the URL to the CentralpointContent Service and to enable access to the server in Admin > Properties: Centralpoint Content Services.
2. They will also need to provide you with the service key which can be generated from the client console Development > Utilities: Service Key.
3. You will need to consume this service; below are steps for how to do this inside Visual Studio.
   a. In the Root/App_WebReferece folder right click and click “Add Service Reference” A dialog box will appear.
   b. Paste the URL provided to you into the address box and click the “Go” button. After communicating with the WCF service the Services box should populate with “CentralpointContent”.
   c. Change the Namespace property on the bottom of the dialogue box to “CentralpointContent” and click OK

see image:


The code below will give you the ability to retrieve any document from Centralpoint by passing the unique intergationId or DataId of the document.
Our service will determine the difference and apply an appropriate filter.
You have access to the following methods:
GetContentInfoXml: Retrive document as XML.
GetContentInfoJson: Retrive document as JSON.
GetContentInfo: Retrieves the document and gives you access to Title, DataId, Exists, IsEnabled, ModuleId, StartDate, EndDate, Summary, and Attributes which is a dictionary of all module attributes where the key is the system name and value is the attribute value.

* If you are going to retrieve XML or JSON and will get the following error: “The maximum string content length quota (8192) has been exceeded while reading XML data.” Then you will need to add readerQuotas to the binding element. (See web. config code example)
** If you are consuming our service from a Centralpoint website then you will need to add the reference to the service to Sync Exclusions. This can be done in the client console Admin > Properties > Sync Exclusions. (the folder is /Root/App_WebReferences/CentralpointContent)


string serviceToken = "931b07e7eb844931b9e75972592c6ffc2c4ad3a19e26425b9048fb7223033c8f";
string intergationId = "VladTestRecord1";
StringBuilder sb = new StringBuilder();

using (CentralpointContent.CentralpointContentClient client = new CentralpointContent.CentralpointContentClient())
{
    try
    {

        sb.AppendFormat("<br><br>GetContentInfoXml <textarea name="textarea" rows="10" cols="80">{0}</textarea><br><br>",
        client.GetContentInfoXml(serviceToken, intergationId));

        sb.AppendFormat("<br><br>GetContentInfoJson: <textarea name="textarea" rows="10" cols="80">{0}</textarea><br><br>",
        client.GetContentInfoJson(serviceToken, intergationId));

        CentralpointContent.ContentInfo contentInfo = client.GetContentInfo(serviceToken, intergationId);
        if (contentInfo.Exists && contentInfo.IsEnabled)
        {
            sb.AppendFormat("<br>ContentInfo:Title: {0}", contentInfo.Title);
            sb.AppendFormat("<br>ContentInfo:DataId: {0}", contentInfo.DataId);
            sb.AppendFormat("<br>ContentInfo:Exists: {0}", contentInfo.Exists);
            sb.AppendFormat("<br>ContentInfo:IsEnabled: {0}", contentInfo.IsEnabled);
            sb.AppendFormat("<br>ContentInfo:ModuleId: {0}", contentInfo.ModuleId);
            sb.AppendFormat("<br>ContentInfo:StartDate: {0}", contentInfo.StartDate);
            sb.AppendFormat("<br>ContentInfo:EndDate: {0}", contentInfo.EndDate);
            sb.AppendFormat("<br>ContentInfo:Summary: {0}", contentInfo.Summary);

            string caption = contentInfo.Attributes.ContainsKey("Caption") ? contentInfo.Attributes["Caption"] : String.Empty;
            sb.Append("<br><br>Get one attribute:Caption: " + caption);

            sb.Append("<br><br>Display All Attributes:");
            foreach (var attribute in contentInfo.Attributes)
                sb.AppendFormat("<br>Key:{0} Value:{1}", attribute.Key, attribute.Value);
        }
        else
            sb.Append("<br>ContentInfo doesn't Exists. The document wasn't found or document is disabled. ");


    }
    catch (FaultException<centralpointcontent.exceptionfaultcontract> ex)
    {
        sb.AppendFormat("<br>FaultException: {0}", String.Format(" ex.Message:{0}<br> ex.Detail.Message:{1}<br>ex.Detail.Description: {2}<br>ex.Detail.AdditionalDetails: {3} ex.Detail.StatusCode:{4}", ex.Message, ex.Detail.Message, ex.Detail.Description, ex.Detail.AdditionalDetails, ex.Detail.StatusCode));
    }
}

divContent.InnerHtml = sb.ToString();
</ centralpointcontent.exceptionfaultcontract >



//Web.config line
<readerQuotas maxDepth="22008192" maxStringContentLength="22008192" maxArrayLength="2516384" maxBytesPerRead="22008192" maxNameTableCharCount="22008192" />



//Whole section Web.config
 <bindings>
     <wsHttpBinding>
   <binding name="WSHttpBinding_ICentralpointContent">
    <readerQuotas maxDepth="22008192" maxStringContentLength="22008192" maxArrayLength="2516384" maxBytesPerRead="22008192" maxNameTableCharCount="22008192" />
   </binding>
     </wsHttpBinding>
</bindings>



Keywords: WCF service, Retrieve record



Related Code Samples Records
Related Taxonomy

Comments:

Be the first to leave a comment.
Please Login to post comments.