Encounterred an error when loading PDF Viewer Web service not listening

Dear Sir,


I encountered the following issue when loading the PDFViewer.



This is my cshtml.

@using Syncfusion.EJ2

@section ControlsSection{

    <div class="control-section">

       <ejs-pdfviewer id="pdfviewer1"

       serviceUrl= "/api/pdfviewer"

       width="100%"

       height="100%"

       showNotificationDialog="true"

       documentPath="Annotations.pdf"

       isAnnotationToolbarOpen="true" >

   </ejs-pdfviewer>

       </div>

}

If I replace the  "/api/pdfviewer" to "https://ej2services.syncfusion.com/production/web-services/api/pdfviewer"

then it is working but I have to load the API locally.


Below is my program.cs code

using Microsoft.Extensions.FileProviders;

using Syncfusion.Licensing;

using WebApplication11.Controllers;


var builder = WebApplication.CreateBuilder(args);


// Add services to the container.

builder.Services.AddControllersWithViews();


if (File.Exists(Directory.GetCurrentDirectory() + "/SyncfusionLicense.txt"))

{

    string licenseKey = File.ReadAllText(Directory.GetCurrentDirectory() + "/SyncfusionLicense.txt");

    SyncfusionLicenseProvider.RegisterLicense(licenseKey);

}


var app = builder.Build();


// Configure the HTTP request pipeline.

if (!app.Environment.IsDevelopment())

{

    app.UseExceptionHandler("/Home/Error");

    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.

    app.UseHsts();

}


app.UseHttpsRedirection();

app.UseStaticFiles();


app.UseRouting();


app.UseAuthorization();


app.MapControllerRoute(

    name: "default",

    pattern: "{controller=Home}/{action=Index}/{id?}");


app.Run();

Besides that, I tried to run your demo projects in my laptop and the pdfviewer is working well too but I can't find any difference between my project and the demo project.

Attached is my project file.

https://drive.google.com/file/d/1Wt026i-c_90e-gXkgHIKvNG54_m4Bf7A/view?usp=sharing


Regards,

WK



1 Reply

SK Shamini Kiruba Sobers Syncfusion Team January 14, 2022 10:25 AM UTC

Hi Chua,

Thank you for the sample. We were able to reproduce the reported issue with the provided sample. And on further analysis, we suspect that you have missed to serialize the JSON Objects. and missed to pass the cache in the Load request Defaultcontroller.cs file. So, the reported issue occurs. We suggest you serialize the JSON Objects in the Program.cs file using the below code snippet to get the issue resolved. We have shared the modified sample and KB link for your reference.



Code snippet:
builder.Services.AddControllers().AddNewtonsoftJson(options =>
{
// Use the default property (Pascal) casing
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});


Kindly try this and revert us, if you have any concerns.

Regards,
Shamini



Loader.
Up arrow icon