Words for Cloud - .NET SDK Examples - error: The remote server returned an error: (401) Unauthorized


#1

Hi!

I have downloaded Aspose.Words for Cloud - .NET SDK Examples from:
https://github.com/aspose-words/Aspose.Words-for-Cloud/tree/master/Examples/DotNET

and want to test ExecuteTemplate.Run();

I have entered the APP SID and APP KEY and uploaded TestExecuteTemplate.doc and TestExecuteTemplateData.txt to my Aspose Cloud account.

When I run RunExamples.cs I get an error:

at Mail_Merge.ExecuteTemplate.Run() in C:\Users\Softwareselskabet\Desktop\Aspose.Words-for-Cloud-master\Examples\DotNET\CSharp\Mail-Merge\ExecuteTemplate.cs:line 28
Exception thrown: ‘Com.Aspose.Storage.ApiException’ in Aspose.Storage-Cloud.dll
error:The remote server returned an error: (401) Unauthorized.

Could someone help me solve the problem?

Complete log:
‘Aspose.Words.Cloud.Examples.CSharp.exe’ (CLR v4.0.30319: DefaultDomain): Loaded ‘C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll’. Skipped loading symbols. Module is optimized and the debugger option ‘Just My Code’ is enabled.
‘Aspose.Words.Cloud.Examples.CSharp.exe’ (CLR v4.0.30319: DefaultDomain): Loaded ‘C:\Users\Softwareselskabet\Desktop\Aspose.Words-for-Cloud-master\Examples\DotNET\CSharp\bin\Debug\Aspose.Words.Cloud.Examples.CSharp.exe’. Symbols loaded.
‘Aspose.Words.Cloud.Examples.CSharp.exe’ (CLR v4.0.30319: Aspose.Words.Cloud.Examples.CSharp.exe): Loaded ‘C:\Users\Softwareselskabet\Desktop\Aspose.Words-for-Cloud-master\Examples\DotNET\CSharp\bin\Debug\Aspose.Words-Cloud.dll’. Skipped loading symbols. Module is optimized and the debugger option ‘Just My Code’ is enabled.
‘Aspose.Words.Cloud.Examples.CSharp.exe’ (CLR v4.0.30319: Aspose.Words.Cloud.Examples.CSharp.exe): Loaded ‘C:\Users\Softwareselskabet\Desktop\Aspose.Words-for-Cloud-master\Examples\DotNET\CSharp\bin\Debug\Aspose.Storage-Cloud.dll’. Skipped loading symbols. Module is optimized and the debugger option ‘Just My Code’ is enabled.
‘Aspose.Words.Cloud.Examples.CSharp.exe’ (CLR v4.0.30319: Aspose.Words.Cloud.Examples.CSharp.exe): Loaded ‘C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll’. Skipped loading symbols. Module is optimized and the debugger option ‘Just My Code’ is enabled.
‘Aspose.Words.Cloud.Examples.CSharp.exe’ (CLR v4.0.30319: Aspose.Words.Cloud.Examples.CSharp.exe): Loaded ‘C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll’. Skipped loading symbols. Module is optimized and the debugger option ‘Just My Code’ is enabled.
‘Aspose.Words.Cloud.Examples.CSharp.exe’ (CLR v4.0.30319: Aspose.Words.Cloud.Examples.CSharp.exe): Loaded ‘C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll’. Skipped loading symbols. Module is optimized and the debugger option ‘Just My Code’ is enabled.
‘Aspose.Words.Cloud.Examples.CSharp.exe’ (CLR v4.0.30319: Aspose.Words.Cloud.Examples.CSharp.exe): Loaded ‘C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll’. Skipped loading symbols. Module is optimized and the debugger option ‘Just My Code’ is enabled.
‘Aspose.Words.Cloud.Examples.CSharp.exe’ (CLR v4.0.30319: Aspose.Words.Cloud.Examples.CSharp.exe): Loaded ‘C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll’. Skipped loading symbols. Module is optimized and the debugger option ‘Just My Code’ is enabled.
Exception thrown: ‘Com.Aspose.Storage.ApiException’ in Aspose.Storage-Cloud.dll
error:The remote server returned an error: (401) Unauthorized.
{“Message”:“Authentication failed!”}
at Com.Aspose.Storage.Api.StorageApi.PutCreate(String Path, String versionId, String storage, Byte[] file)
at Mail_Merge.ExecuteTemplate.Run() in C:\Users\Softwareselskabet\Desktop\Aspose.Words-for-Cloud-master\Examples\DotNET\CSharp\Mail-Merge\ExecuteTemplate.cs:line 28
Exception thrown: ‘Com.Aspose.Storage.ApiException’ in Aspose.Storage-Cloud.dll
error:The remote server returned an error: (401) Unauthorized.
{“Message”:“Authentication failed!”}
at Com.Aspose.Storage.Api.StorageApi.PutCreate(String Path, String versionId, String storage, Byte[] file)
at Document.ConvertToAnyFormat.Run() in C:\Users\Softwareselskabet\Desktop\Aspose.Words-for-Cloud-master\Examples\DotNET\CSharp\Document\ConvertToAnyFormat.cs:line 32
The program ‘[5700] Aspose.Words.Cloud.Examples.CSharp.exe’ has exited with code 0 (0x0).

VS executeTemplate.png (126.7 KB)
RunExamples.png (120.2 KB)
Aspose.png (226.3 KB)
Common.png (155.0 KB)


#2

@Sophus

Thank you for contacting Aspose Support.

https://github.com/aspose-words/Aspose.Words-for-Cloud/tree/master/Examples/DotNET SDK is deprecated. We have released fully reworked version of .NET SDK, please check this blog post for more details.

Considering this, please use this updated SDK https://github.com/aspose-words-cloud/aspose-words-cloud-dotnet and let us know if you face any error.


#3

Thanks for the quick reply. Will try it and let you know. I also posted this in the Aspose forum but cant find it and delete.


#4

@Sophus

Please post all queries regarding Aspose REST APIs in this forum. https://forum.aspose.com/ is for native APIs.


#6

@sohail.aspose

I created a ASP.NET web app project. I followed the instructions and added Aspose.Words Cloud:
Open the Solution Explorer.
Right-click on a project within your solution.
Click on Manage NuGet Packages…
Click on the Browse tab and search for “Aspose.Words-Cloud”.
Click on the Aspose.Words-Cloud package, select the appropriate version in the right-tab and click Install.

In the old dotnet examples it was strait forward to run different examples but how do I do it with the SDK.

I want to test the mail merge functions which can be found here;

Can I somehow added it to default.aspx.cs and run ExecuteMailMergeTest.cs for example with the sample template and template data?


#7

@Sophus

The above steps you performed are to add “Aspose.Words-Cloud” in your own project.

If you want to run SDKs Unit Tests then simply clone the repository:

git clone https://github.com/aspose-words-cloud/aspose-words-cloud-dotnet.git

Open the project (Aspose.Words.Cloud.Sdk.sln) in Visual Studio, set your App Key and App SID in OAuthTests.cs file and most importantly set AppURL to https://api.aspose.cloud/v1.1

Open the required Test file e.g. ExecuteMailMergeTest.cs and run a Unit Test e.g. TestPutExecuteMailMergeOnline() by clicking on its method name or inside method body and press
Ctrl + R then immediately Ctrl + T.

You may Google how to run Unit Tests in Visual Studio for more details.


#8

Hi @mateensajjad.

It worked. I know this not the scope for the support forum in general. So thank you.

BR.


#9

@Sophus

Good to know that it worked. Please keep using Aspose for Cloud APIs.


#10

This is not working in my case. I am using the current git aspose.words.cloud sdk https://github.com/aspose-words-cloud/aspose-words-cloud-dotnet

|Error|CS0176|Member ‘OAuthTests.AppKey’ cannot be accessed with an instance reference; qualify it with a type name instead|Aspose.Words.Cloud.Sdk.Tests|C:\Users\welcome\Desktop\aspose-words-cloud-dotnet-master\aspose-words-cloud-dotnet-master\Aspose.Words.Cloud.Sdk.Tests\Infrastructure\OAuthTests.cs|67|Active|


#11

@ssana

The SDK is working perfectly fine our end. Please ensure you have correctly integrated following NuGet packages in your project:

  1. Aspose.Words-Cloud (v18.9.0)
  2. Newtonsoft.Json (v18.9.0)
  3. Aspose.Storage-Cloud (v18.3.0)

Manage NuGet Packages… window should look as follows: