Is there an example C# project?

  • 3
  • Question
  • Updated 5 years ago
  • Answered
I'm working on a way to make Replicon easier to use for people at my company through an app written in C#. However, the only example I've found (RepliConnectLinqExample) references very obscure namespaces and doesn't compile. I'm having no luck finding a better example of how to connect to Replicon externally. I really hope there's a better set of examples or a demo app somewhere because the documentation is extremely light in this area. It seems to assume that you've already connected and that you know exactly what you're doing, which is not the case for me.

(Originally posted by bandtank)
Photo of Archived Post

Archived Post, Official Rep

  • 2132 Posts
  • 7 Reply Likes

Posted 6 years ago

  • 3
Photo of Archived Post

Archived Post, Official Rep

  • 2132 Posts
  • 7 Reply Likes
Hi,

Thank you for using Replicon Community.

Steps on how to connect to Replicon externally are provided at the below URL:- 

Getting Started with the RepliConnect API (refer to Accessing RepliConnect via a Static URL or Accessing RepliConnect API sections.)

For a complete example of C# refer to the Example of a Complete Request using C# section on the same page. 

Feel free to contact our support team should you face issues with your C# code. 



Thanks,

Lingaraj



 

(Originally posted by Lingaraj Dharwad)
Photo of Archived Post

Archived Post, Official Rep

  • 2132 Posts
  • 7 Reply Likes
I already tried that example project, but there's no instructions about how to actually get it to compile. I installed NewtonSoft-Json via package manager, but there are still 20+ compilation errors. Specifically, the errors seem to be related to missing classes or references, but I have no idea what to add because there's no documentation. 1) JavaScriptObject - "C#: Unknown type 'JavaScriptObject'" 2) JavaScriptArray - "C#: Unknown type 'JavaScriptArray'" 3) new JsonReader(reader) - "An instance of an abstract class can not be created." I would send this directly to support, but this kind of stuff needs to be available to the public because your example documentation is very incomplete.

(Originally posted by bandtank)
Photo of Archived Post

Archived Post, Official Rep

  • 2132 Posts
  • 7 Reply Likes
Hi,

Thanks for your suggestion, we will have the required changes made and make this available to everyone soon. 

Thanks,

Lingaraj



(Originally posted by Lingaraj Dharwad)
Photo of Archived Post

Archived Post, Official Rep

  • 2132 Posts
  • 7 Reply Likes
Can you post the new code to this question.

(Originally posted by tony.klotz)
Photo of Archived Post

Archived Post, Official Rep

  • 2132 Posts
  • 7 Reply Likes
Please post the new code for this question.

(Originally posted by tony.klotz)
Photo of Archived Post

Archived Post, Official Rep

  • 2132 Posts
  • 7 Reply Likes
Hi Tony,

Please find attached a sample program in REST method for getting a specific project details.

Kindly rename the extension from .txt to .cs.

Thanks,
Lingaraj




(Originally posted by Lingaraj Dharwad)
Photo of hussain

hussain

  • 7 Posts
  • 0 Reply Likes
I could'nt see any attachment in this post please can you instruct me where can i find this?
Photo of Lingaraj Dharwad

Lingaraj Dharwad, Product Champion

  • 1100 Posts
  • 47 Reply Likes
Hi Hussain,

Thank you for using Replicon Community,

Let me know if you are using Gen3 or Gen2 version of our application? 

Regards,
Lingaraj
Photo of hussain

hussain

  • 7 Posts
  • 0 Reply Likes
Thank You Lingaraj for your reply, i am not able find the version Gen3 or Gen2 can you please tell me how can i identify version of application?

For your futher info, right now i am using trial account of replicon so please also tell me that in trial account may i use API of replicon?
(Edited)
Photo of Lingaraj Dharwad

Lingaraj Dharwad, Product Champion

  • 1100 Posts
  • 47 Reply Likes
Yes, we call them Web services in Gen3. If your using a trial, then it's likely that your on Gen3. Below URL has the information on getting started with Web services.

http://www.replicon.com/help/accessin...

Let me know if that helps.

Regards,

Lingaraj
(Edited)
Photo of hussain

hussain

  • 7 Posts
  • 0 Reply Likes
Thanks its good i found this before but getting a problem when accessing API using C# code, got an error "The remote server returned an error: (401) Unauthorized." please have a look at the following code

class Program
{  
            // Modify these to point at your Replicon instance         
            private const string companyKey = "*******";
            private const string apiUrl = "https://na1.replicon.com/" + companyKey + "/RemoteAPI/RemoteAPI.ashx/8.29.28/";
            private const string loginname = "**********";
            private const string password = "**********";

            private static readonly JsonSerializer jsonSerializer = new JsonSerializer();

            static void Main(string[] args)
            {
               
               // first tried with this
                string postData = "Action=Query&QueryType=UserAll,&DomainType=Replicon.Domain.User";

               // then tried with this
                postData = "Action=BeginSession";

                PerformApiRequest(postData);
            }           

            
            private static string PerformApiRequest(object apiRequest)
            {
                var request = (HttpWebRequest)WebRequest.Create(apiUrl);
                string responseString = string.Empty;
                request.Credentials = new NetworkCredential(companyKey + "\\" + loginname, password);
                request.PreAuthenticate = true; // send auth on first request 
                request.Method = "POST";                
                request.ContentType = "application/json; charset=utf-8";
                request.Headers.Add("X-Replicon-Security-Context", "User");

                // Send API request in JSON format 
                using (var requestStream = request.GetRequestStream())
                using (var writer = new StreamWriter(requestStream, Encoding.UTF8))
                    jsonSerializer.Serialize(writer, apiRequest);

                // Receive API request and convert into JSON objects 
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                }
                
                return responseString;
            }
 }
==================================================================

on this line i found an runtime error The remote server returned an error: (401) Unauthorized.


 using (var response = (HttpWebResponse)request.GetResponse())
                {
                    responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                }

=================================================================

please suggest what is the purpose of this error ? Am i really not authorize or i am doing something wrong? if i am not authorize to view all users so why its still fail for "BeginSession" Query.

the line 

postData = "Action=BeginSession";

is an optional just to check whether its work or not. please can you help me on that?

Thanks Lingaraj
(Edited)
Photo of Lingaraj Dharwad

Lingaraj Dharwad, Product Champion

  • 1100 Posts
  • 47 Reply Likes
Hi Hussain,

The issue with the way you have provided the login name. It should be in the format "companykey\\loginname". 

You can also refer to the below post:

https://community.replicon.com/replicon/topics/web-services-authentication

Let me know if that helps.

Regards,
Lingaraj
Photo of hussain

hussain

  • 7 Posts
  • 0 Reply Likes
Hey Lingaraj i have used the same login name format as you defined

like in above code in "ProcessApiRequest()" method at third line i write

 request.Credentials = new NetworkCredential(companyKey + "\\" + loginname, password);

i am already using this format "companyKey + "\\" + loginname" please suggest what else can be possible to resolve this problem.

Thanks
Photo of Lingaraj Dharwad

Lingaraj Dharwad, Product Champion

  • 1100 Posts
  • 47 Reply Likes
Hi Hussain,

The code you are trying to use is meant for Gen2 instances. Could you post a screenshot of your instance? For Gen3 you will have to use a different JSON request altogether. 

We need to first confirm if you are using Gen2 or Gen3.

Regards,
Lingaraj
Photo of hussain

hussain

  • 7 Posts
  • 0 Reply Likes
I have uploaded image of screen shot there please check on this url

http://tinypic.com/r/6zskqp/8
Photo of Lingaraj Dharwad

Lingaraj Dharwad, Product Champion

  • 1100 Posts
  • 47 Reply Likes
You are on Gen3.

Please follow the steps mentioned in the link below: 

http://www.replicon.com/help/accessing-the-details-of-the-services?destination=help/1000297/1000298&...

A sample code to GetAllReports and GenerateReport in C#.

Please change the extension to .zip and extract the contents.



Let me know if this helps.

Regards,
Lingaraj
Photo of hussain

hussain

  • 7 Posts
  • 0 Reply Likes
Ok i will try with this Thank you Lingaraj
Photo of hussain

hussain

  • 7 Posts
  • 0 Reply Likes
Hi Lingaraj,

I tried with the code you provided but i still getting the same error 401 Unauthorize, please confirm do i need to change any thing else except username and password and company?, it seems nothing else needs to change
Photo of Lingaraj Dharwad

Lingaraj Dharwad, Product Champion

  • 1100 Posts
  • 47 Reply Likes
Please ensure you are set up with all the major roles & permissions: Billing Manager, Payroll Manager, Project Management Administrator, Cost Manager and others which are available in your account. Note that not all may be applicable to your specific instance. 

The screenshot below shows how your profile should ideally show up: 



If issue still persists, kindly contact the support team as this needs further investigation.

Regards,
Lingaraj
Photo of Dean Holden

Dean Holden

  • 1 Post
  • 0 Reply Likes
I'm looking for a C# example for CreateReportGenerationBatch .  Is there one out there somewhere?  I found the Sample_Report_Generation example very helpful, but I have some reports that timeout, so I need to run them in the background.

Thanks,
Dean
Photo of Sayantan Choudhury

Sayantan Choudhury, Tier 3 Cloud Operations Engineer

  • 7 Posts
  • 1 Reply Like
Hi Dean,

Please find the steps to Generate a report using batch as follows:

1. Use "ReportService1.svc/CreateReportGenerationBatch" service to get the ReportGenerationBatchURI.
Request JSON object sample:
{
  "reportParameters": [
    {
      "reportUri": "ReportURI",
      "filterValues": [],
      "outputFormatUri": "OutputFormatURI"
    }
  ]
}
Response JSON object sample:
{
  "d": "ReportGenerationBatchURI"
}

2. Use "BatchManagementService1.svc/ExecuteInBackground" service to execute the ReportGenerationBatchURI in background.
Request JSON object sample:
{
  "batchUri": "ReportGenerationBatchURI"
}
Response JSON object sample:
{
  "d": null
}

3. Use "BatchManagementService1.svc/GetStatus" service to get the status of the execution from the previous step.
Request JSON object sample:
{
  "batchUri": "ReportGenerationBatchURI"
}
Response JSON object sample:
{
  "d": {
    "batchUri": "ReportGenerationBatchURI",
    "creationTime": {
      "day": day,
      "hour": hour,
      "minute": minute,
      "month": month,
      "second": second,
      "year": year
    },
    "endTimestamp": {
      "day": day,
      "hour": hour,
      "minute": minute,
      "month": month,
      "second": second,
      "year": year
    },
    "executionState": "urn:replicon-service-model:batch-execution-state:succeeded",
    "items": [],
    "message": null,
    "name": "Execute",
    "overallProgress": {
      "currentProgress": number,
      "maximumProgress": number
    },
    "startTimestamp": {
      "day": day,
      "hour": hour,
      "minute": minute,
      "month": month,
      "second": second,
      "year": year
    }
  }
}
Keep repeating Step 3 at a specific interval and check the value of "executionState" from the response JSON Object until the value changes to "urn:replicon-service-model:batch-execution-state:succeeded" (check for the last sub string after ':' until the sub string is "succeeded"). Once the value is "succeeded", go to step 4. Note that if the data is huge, this might take a long time.

4. Use "ReportService1.svc/GetReportGenerationBatchResults" service to get the result of the ReportGenerationBatchURI that was created in step 1.
Request JSON object sample:
{
  "reportGenerationBatchUri":"ReportGenerationBatchURI"
}
Response JSON object sample:
{
  "d": {
    "reportGenerationResults": [
      {
        "error": null,
        "filterValues": [],
        "payload": "ReportContent",
        "reportUri": "ReportURI"
      }
    ]
  }
}
The "payload" field will contain the Report content.

NOTE: Do not use this service for regular report generation. Only use this service for pulling up large data.

Regards,
Sayantan
(Edited)
Photo of Archived Post

Archived Post, Official Rep

  • 2132 Posts
  • 7 Reply Likes
Hi Tony,

New code posted as an attachment on the post above.

Thanks,
Lingaraj


(Originally posted by Lingaraj Dharwad)
Photo of Archived Post

Archived Post, Official Rep

  • 2132 Posts
  • 7 Reply Likes
Can you post a javascipt example?

(Originally posted by tony.klotz)
Photo of Archived Post

Archived Post, Official Rep

  • 2132 Posts
  • 7 Reply Likes
Hi Tony,

We will have one of our specialists call you tomorrow. Please let us know a suitable time to contact you.

Thank You!



Replicon .

(Originally posted by Lingaraj Dharwad)