Posted Thu, 06 Feb 2020 14:05:38 GMT by Vural Cakir
Hello colleagues,

for an university project im developing a C# class which connects to the Rest API of Docuware (Cloud Plattform). I developed a Post-Reqeust to get the access to the Rest API. It worked perfectly. Next I developed a Get-Reqeust to get the first 5 Documents in the File Cabinet. This also works perfectly. My biggest Problem is to "Upload  a file and create a document at the same time". First I used Postman (with the Postman package which is provided by you) to test the command, than I tried it in C# Consol Programm. In Postman everything works perfectly but in C# I get the Error:


<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="/DocuWare/Platform/Content/errors.xslt"?><s:Error Uri="http://studenthsnr.docuware.cloud/DocuWare/Platform/FileCabinets/9f3d1ebb-618d-4c8e-8af3-6067ca0a3a88/Documents" Method="POST" StatusCode="500" Status="Internal Server Error" xmlns:s="http://dev.docuware.com/schema/public/services"><s:ShowException>false</s:ShowException><s:Message>Value cannot be null.
Parameter name: input</s:Message><s:Exception>ArgumentNullException: Value cannot be null.
Parameter name: input</s:Exception></s:Error>


This ist my Codding:

var xmlStream = new FileStream(xmlFilePath, FileMode.Open);
            var docStream = new FileStream(docFilePath, FileMode.Open);


            HttpContent xmlFileStreamContent = new StreamContent(xmlStream);
            HttpContent docFileStreamContent = new StreamContent(docStream);

            var formData = new MultipartFormDataContent();


            formData.Add(xmlFileStreamContent, "document");//xmlData
            formData.Add(docFileStreamContent, "file[]");//actual Document

            var response2 = await client.PostAsync("https://{Plattform}/FileCabinets/{Cabinet Id}/Documents", formData);
            var responseBody2 = await response2.Content.ReadAsStringAsync();
            var responseHeader2 = response2.EnsureSuccessStatusCode();
            Console.WriteLine(responseBody2);

The Authorization is not the Problem, I checked it.

I would be happy if you can provide a solution.


Best regards Vural

 
Posted Thu, 06 Feb 2020 15:33:11 GMT by Joe Kaufman Bell Laboratories Inc No longer there
Vural,

Not sure if it is allowable for your project, but have you tried using the very nice DocuWare packages that wrap the API in easy-to-use C# code? I have found that for certain operations, using the API with straight POSTs and GETs is problematic (I am doing a lot of that from Visual Foxpro). You can learn more about the .NET packages at:

https://developer.docuware.com/dotNet/66b2ed1e-2aef-452a-97cd-5014bbf0242b.html

But if you have to use the more raw GETs and POSTs (as I imagine a college project might require you to do), I am not sure why your code does not work. In reviewing my Foxpro code, your entry point appears to be correct, but I do not try to upload and index the document all at once. I upload it, then index it using a separate POST. On what line are you getting the actual error? Have you tried just uploading the file, and does that succeed? The more you can break the transaction down the better you can debug the problem. The issue might lie with the XML not being in a format DocuWare expects, for example.

Sorry I cannot be of more help, as on the C# side I use the DocuWare Nuget packages to make life a whole lot easier.

Good luck!
Joe Kaufman
Posted Fri, 07 Feb 2020 08:52:57 GMT by Vural Cakir

Hello Joe,

first of all thank you verry much for the quick response!!! Your support is awesome!

Im getting the Error when Im ensuring the Status Code in the Line:

var responseBody2 = await response2.Content.ReadAsStringAsync()

In our study  the use case is to use native C# an not depend on third party Software. I updated my Code and now im getting the following Error.

{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:{  Date: Fri, 07 Feb 2020 08:50:29 GMT  Connection: keep-alive  Cache-Control: s-maxage=0, private  Server: Microsoft-IIS/10.0  Server: curious  Server: .  Server: .  Server: .  Strict-Transport-Security: max-age=31536000;includeSubDomains  Content-Security-Policy: script-src https://*.docuware.cloud https://saas.docuware.com https://go.docuware.com https://widget.surveymonkey.com https://secure.surveymonkey.com 'self' blob: dwcloudstatic.azureedge.net cdnjs.cloudflare.com ajax.aspnetcdn.com ajax.googleapis.com *.msecnd.net https://*.userlane.com use.fontawesome.com 'unsafe-inline' 'unsafe-eval'  Expect-CT: max-age=0, report-uri='https://dw-csp-reporter.azurewebsites.net/'  X-Xss-Protection: 1; mode=block  Referrer-Policy: strict-origin  X-Content-Type-Options: nosniff  X-Robots-Tag: noindex, nofollow  x-served-by: pf2300003Y  Content-Type: application/xml; charset=utf-8  Content-Length: 594}}

I will try to do as you said for now. First upload it, then index it using a separate POST.

Thank you for everything the foundation of yours is really awesome!

Posted Fri, 07 Feb 2020 12:09:10 GMT by Vural Cakir
Hello Joe,

I have a second Problem, now Im trying to use Docuwares Classes from the link you posted. Via Nuget i installed DocuWarePlatformApi. I tried to connect to the Service  with the following code

using DocuWare.Platform.ServerClient;
using System;


namespace PRG_DocuWare_Use_Own_API
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("Hello World!");
            var conn = ServiceConnection.Create(new Uri("https://studenthsnr.docuware.cloud/DocuWare/Platform"), "username", "password");
              
        }
    }
}

I get the Following error: 

System.IO.FileLoadException: "Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=............'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)"

Maybe you have a solution.


Best regards

Vural
Posted Fri, 07 Feb 2020 16:16:22 GMT by Joe Kaufman Bell Laboratories Inc No longer there
Vural,

The code for establishing a connection looks correct, but the error is not really related to that, I don't think. Something is going wrong when a certain assembly tries to get loaded.

It is sort of a new version of "DLL Hell", and it sometimes relates to packages not being installed correctly (or versions being off). Assembly configuration is still a chore sometimes in the .NET world, but I do not know why you would be having versioning issues if you installed the latest DocuWare packages from NuGet.

I think you may have a conflict with .NET Core vs. .NET Framework. What sort of application are you trying to code? That is, what is the project type? I assume you are using Visual Studio Code and not the full-blown (paid) version of Visual Studio? Here are a few links I found that talks about issues with the ConfigurationManager:

https://github.com/pusher/pusher-websocket-dotnet/issues/34

https://stackoverflow.com/questions/46360716/cant-use-system-configuration-configuration-manager-in-a-net-standard2-0-libra/50937932

https://stackoverflow.com/questions/47098698/how-to-use-net-framework-from-net-core

As you can see, StackOverflow is your friend.  *smile*  I am betting this is just a configuration/reference issue related to the type of application you are building. If you can develop a .NET Framework application using Windows Forms I know the stuff works, as that is what we use. I have not tried any DocuWare code as part of an ASP.NET or .NET Core project.

Good luck!
​​​​​​​
Joe Kaufman
Posted Wed, 12 Feb 2020 11:53:02 GMT by Vural Cakir
Hello Joe,

you were right, I used .Net Framework and everything worked perfectly!

Thank you for your support and have a nice day!


Best regards Vural
Posted Wed, 12 Feb 2020 14:59:53 GMT by Joe Kaufman Bell Laboratories Inc No longer there
Vural,

Glad to hear it! It was just a lucky guess on my part, as all the versions of .NET make my head hurt...

Thanks,
Joe Kaufman

You must be signed in to post in this forum.