Signing

Creating a simple document order with one subject (Danish NemID)

678 views August 3, 2017 October 9, 2017 6

Use the DocumentService to create a document order request. A document order may contain several documents, tasks and subjects (people). This is a simple example where one subject must sign one document and where the result is a plain NemID SDO (Signed Document Object)

The C# example has been updated for compatibility with DocumentService-v3

[TestMethod]
public void How_to_create_a_simple_document_order_with_one_subject_and_one_document_using_Danish_NemID()
{
	// The document id is what you get in response when uploading a document to the SDS
	string documentId = "04092013551868wie4tdlw9n8e6s834f3iwm92yq5i8d3gkgqit3vpm6ed";
	var request = new createrequestrequest
	{
		password = "Bond007",
		service = "demo",
		request = new request[]
		 {
			 new request
			 {
				 clientreference = "cliref1",
				 language = "da",
				 profile = "demo",
				 document = new document[]
				 {
					 new sdsdocument
					 {
						 id = "doc_1",
						 refsdsid = documentId,
						 description = "Terms and conditions"
					 }
				 },
				 subject = new subject[]
				 {
					 new subject
					 {
						 id = "subj_1",
						 nationalid = "1909740939"
					 }
				 },
				 task = new task[]
				 {
					 new task
					 {
						 id = "task_1",
						 subjectref = "subj_1",
						 bundleSpecified = true,
						 bundle = false,
						 documentaction = new documentaction[]
						 {
							  new documentaction
							  {
								  type = documentactiontype.sign,
								  documentref = "doc_1"
							  }
						 },
						 signature = new signature[]
						 {
							 new signature
							 {
								 responsiveSpecified=true,
								 responsive = true,
								 method = new method[]
								 {
									 new method
										 {
											value = "nemid-sign"
										 }
								 }
							 }
						 }
					 }
				 }
			 }
		 }
	};
	createrequestresponse response;
	using (var client = new DocumentEndPointClient())
	{
		response = client.createRequest(request);
	}
	String signHereUrl =
		String.Format("https://preprod.signicat.com/std/docaction/demo?request_id={0}&task_id={1}", response.requestid[0], request.request[0].task[0].id);
	Console.WriteLine(signHereUrl);
	Assert.IsNotNull(response);
	Assert.IsNull(response.artifact);
	Assert.IsNotNull(response.requestid);
}
package com.signicat.signature;

import com.signicat.document.v2.*;
import org.junit.Assert;
import org.junit.Test;

import javax.xml.ws.Service;

public class CreateRequestWithSubject {

	@Test
	public void how_to_create_a_simple_document_order_with_one_subject_and_one_document_using_Danish_NemID()
			throws Exception
	{
		// The document id is what you get in response when uploading a document to the SDS
		String documentId = "17032016pvd9kv2k2pyorq8zniq3x01h2dircxhw6hwjx2i5i9ebjn0a6";

		CreateRequestRequest createRequestRequest = new CreateRequestRequest();
		createRequestRequest.setPassword("Bond007");
		createRequestRequest.setService("demo");

		Request request = new Request();
		request.setClientReference("cliref1");
		request.setLanguage("da");
		request.setProfile("demo");

		SdsDocument document = new SdsDocument();
		document.setId("doc_1");
		document.setRefSdsId(documentId);
		document.setDescription("Terms and conditions");
		request.getDocument().add(document);

		Subject subject = new Subject();
		subject.setId("subj_1");
		subject.setNationalId("1909740939");

		Task task = new Task();
		task.setId("task_1");
		task.setSubjectRef("subj_1");
		task.setBundle(false);

		DocumentAction documentAction = new DocumentAction();
		documentAction.setType(DocumentActionType.SIGN); // Sign or View
		documentAction.setDocumentRef("doc_1"); // Any identifier you'd like
		task.getDocumentAction().add(documentAction);

		Signature signature = new Signature();
		signature.getMethod().add("nemid-sign"); // The name of the signature method(s)
		task.getSignature().add(signature);

		request.getTask().add(task);

		createRequestRequest.getRequest().add(request);

		Service documentService = new DocumentService();
		DocumentEndPoint client = documentService.getPort(DocumentEndPoint.class);
		CreateRequestResponse response = client.createRequest(createRequestRequest);

		String signHereUrl =
				String.format("https://preprod.signicat.com/std/docaction/demo?request_id=%s&task_id=%s",
						response.getRequestId().get(0), createRequestRequest.getRequest().get(0).getTask().get(0).getId());
		System.out.println(signHereUrl);
		Assert.assertNotNull(response);
		Assert.assertNull(response.getArtifact());
		Assert.assertNotNull(response.getRequestId());
	}
}

Was this helpful?