I have been using DocuSign SOAP based API service to parse the XML that DocuSign posts for each recipient/envelope status updates.
Within .net web application, here is how I am parsing the XML.
Using sr As New StreamReader(FileName)
Dim xml As String = sr.ReadToEnd()
Dim reader As XmlReader = New XmlTextReader(New StringReader(xml))
Dim serializer As New XmlSerializer(GetType(DocuSignServ.DocuSignEnvelopeInformation), "http://www.docusign.net/API/3.0")
Dim envelopeInfo As DocuSignEnvelopeInformation = TryCast(serializer.Deserialize(reader), DocuSignEnvelopeInformation)
End Using
I would like to know if I can parse the XML with RESTful API here. I could not find a way to convert XML to an object based upon RESTful API.
I tried something like this,
Using sr As New StreamReader(FileName)
Dim xml As String = sr.ReadToEnd()
Dim reader As XmlReader = New XmlTextReader(New StringReader(xml))
Dim serializer As New XmlSerializer(GetType(DocuSign.eSign.Model.EnvelopesInformation), "http://www.docusign.net/API/3.0")
Dim envelopeInfo As DocuSign.eSign.Model.EnvelopesInformation = TryCast(serializer.Deserialize(reader), DocuSign.eSign.Model.EnvelopesInformation)
End Using
I am not able to convert the XML to an envelope object here.
Please advise,
Thanks,
Minal
No, the RESTful API works on different data model and you cannot parse DocuSign Connect XML with RESTful API data model.
Related
I am using eSignature REST API v2.1 Java to create envelope. Document is in html format with non English language. On the signing page these non English is not displayed properly. How to handle this case? Thanks,
String htmlDoc = ".... .... <p>Signera arbetsorderavtal för anställningsnummer</p> ......";
Document document = new Document();
document.setDocumentId("1");
document.setName("name");
document.setDocumentBase64(Base64.getEncoder().encodeToString(htmlDoc));
document.setFileExtension("html");
envelopeDefinition.setDocuments(Arrays.asList(document));
Output:
Expecting proper display of the foreign language.
My code is:
String htmlDoc = "<p>Signera arbetsorderavtal för anställningsnummer</p>"; // removed <html> & <body>
byte[] byteArray = htmlDoc.getBytes(**StandardCharsets.UTF_8**);
Document document = new Document();
document.setDocumentId("1");
document.setName("name");
document.setFileExtension("html");
document.setDocumentBase64(Base64.getEncoder().encodeToString(byteArray));
Output:
Signing Page
You are not telling Java that the string is Unicode Transformation Format or UTF-8.
Here is your code fixed:
String htmlDoc = ".... .... <p>Signera arbetsorderavtal för anställningsnummer</p> ......";
Document document = new Document();
document.setDocumentId("1");
document.setName("name");
document.setDocumentBase64(Base64.getEncoder().encodeToString(htmlDoc.getBytes(StandardCharsets.UTF_8)));
document.setFileExtension("html");
envelopeDefinition.setDocuments(Arrays.asList(document));
I have a SAML implementation which works fine with JumpCloud, OneLogin and other providers, however integration with Microsoft Azure AD is proving difficult. We received the error
AADSTS75005: The request is not a valid Saml2 protocol message.
Whenever we send our requests over. I have tried the solutions mentioned here and here but neither fixes the issue for us.
My code to create the SAML Request, which opens in a new window via some Javascript is:
Using sw As StringWriter = New StringWriter()
Dim xws As XmlWriterSettings = New XmlWriterSettings()
xws.OmitXmlDeclaration = True
Dim assertionUrl As String = "OUR URL"
Dim issuer As String = "OUR ISSUER TEXT"
dim id as string = "_" + System.Guid.NewGuid().ToString()
dim issue_instant as string = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
Using xw As XmlWriter = XmlWriter.Create(sw, xws)
xw.WriteStartElement("samlp", "AuthnRequest", "urn:oasis:names:tc:SAML:2.0:protocol")
xw.WriteAttributeString("ID", id)
xw.WriteAttributeString("Version", "2.0")
xw.WriteAttributeString("IssueInstant", issue_instant)
xw.WriteAttributeString("ProtocolBinding", "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST")
xw.WriteAttributeString("AssertionConsumerServiceURL", assertionUrl)
xw.WriteStartElement("saml", "Issuer", "urn:oasis:names:tc:SAML:2.0:assertion")
xw.WriteString(issuer)
xw.WriteEndElement()
xw.WriteStartElement("samlp", "NameIDPolicy", "urn:oasis:names:tc:SAML:2.0:protocol")
xw.WriteAttributeString("Format", "urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified")
xw.WriteAttributeString("AllowCreate", "true")
xw.WriteEndElement()
xw.WriteStartElement("samlp", "RequestedAuthnContext", "urn:oasis:names:tc:SAML:2.0:protocol")
xw.WriteAttributeString("Comparison", "exact")
xw.WriteStartElement("saml", "AuthnContextClassRef", "urn:oasis:names:tc:SAML:2.0:assertion")
xw.WriteString("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport")
xw.WriteEndElement()
xw.WriteEndElement() ' RequestedAuthnContext
xw.WriteEndElement()
End Using
If (format = AuthRequestFormat.Base64)
Dim toEncodeAsBytes As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(sw.ToString())
Return System.Convert.ToBase64String(toEncodeAsBytes)
End If
Return Nothing
End Using
We then redirect the user to: https://login.microsoftonline.com/OUR_APP_ID/saml2?SAMLRequest= followed by the encoded string
I have base64decoded my result, and read it as a raw string and the XML appears valid to me. I have even gone so far as to take the example Request from Azure AD and hard-coded my implementation to that, with replaced issuer/instant/id etc. This leads me to believe it is an encoding issue in my request. However, the changed encoding in Dushyant Gill's answer does not resolve my problem either.
I've found various other forum posts where other software vendors have mentioned that they have had to apply changes to their SAML implementations when their customers have complained that it didn't work with Azure - however I've yet to find what their resolution was.
If you are using HTTP redirect binding (which is suggested by
We then redirect the user to
) , then the SAMLRequest has to be encoded using DEFLATE encoding. Please see section 3.4.4 of http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf
The specific scenario that we are attempting to solve for our API solution is to create an envelope using a template and to replace the template document with a user specified document. DocuSign's documentation on creating a composite template show the steps for the serverside template and inline templates clearly, and this functionality is working correctly for us. However, the portion of the XML string containing the alternate document does not affect the template. Here is the link to DocuSign's example followed by the code snippet regarding document portion of the composite template.
https://www.docusign.com/p/APIGuide/Content/Sending%20Group/Rules%20for%20CompositeTemplate%20Usage.htm
<Document>
<ID>1</ID>
<Name>Form Document</Name>
<PDFBytes>PDF_BYTES_GO_HERE</PDFBytes>
<TransformPdfFields>true</TransformPdfFields>
<FileExtension>pdf</FileExtension>
</Document>
We have tried multiple variations of breaking down the pdf into bytes to insert into the "PDF_BYTES_GO_HERE" portion.
Here is the code we used to get the pdf bytes, convert them to a string and insert into the tag.
Dim fs As FileStream
fs = File.Open(filePath, FileMode.Open)
Dim bytes As Byte() = New Byte(fs.Length - 1) {}
fs.Read(bytes, 0, System.Convert.ToInt32(fs.Length))
fs.Close()
Dim byteString As String = System.Convert.ToBase64String(bytes, 0, bytes.Length)
byteString is the string that we then use in the XML string.
"<Document>" & _
"<documentId>1</documentId>" & _
"<name>DOCUSIGN API TEST</name>" & _
"<PDFBytes>" & byteString & "</PDFBytes>" & _
"<TransformPdfFields>false</TransformPdfFields>" & _
"<FileExtension>pdf</FileExtension>" & _
"</Document>" & _
What type of data is expected within the tag and what is the best way to convert a pdf into that data?
Based on the documentation you've linked to, and the code sample you included, it seems as though you're using the DocuSign SOAP API. If that's the case, then the DocuSign SOAP API guide will be a useful reference for you. As the guide specifies, the PDFBytes property expects a base64-encoded byte stream that represents the document contents:
Are you manually constructing the XML payload? If so, you might instead want to consider adding a Service Reference to your project for the DocuSign WSDL, and then using the proxy classes (i.e., DocuSign object model) that come from that to construct the payload and subsequently send the envelope. If you go this route, the API guide contains code examples in a couple different languages that illustrate the setting of the PDFBytes property during Envelope creation -- starting on page 62. For example:
C#
// Attach the document(s)
envelope.Documents = new DocuSignWeb.Document[1];
DocuSignWeb.Document doc = new DocuSignWeb.Document();
doc.ID = "1";
doc.Name = "Document Name";
doc.PDFBytes = [Location of Document];
envelope.Documents[0] = doc;
PHP
// Attach the document
$doc = new Document();
$doc->ID = "1";
$doc->Name = "Picture PDF";
$doc->PDFBytes = file_get_contents("docs/picturePdf.pdf");
$env->Documents = array($doc);
Perhaps try modeling your approach after one of these examples (in VB, rather than C# or PHP)?
I'm using Azure media services. I tried to obtain a SAS by creating a locator, and then getting the baseURI property of it. The SAS I got by doing that is:
https://rfsstorage.blob.core.windows.net/asset-02b45419-74fd-48cc-bdb8-dd66e0d88055
But is that really a SAS? Or is it something else? It certainly doesn't work with other code that I borrowed from the internet that expects a SAS.
Here is the few lines of code I used to obtain the SAS:
Public Sub OtainSAS(ByVal Filename As String)
Dim mediaServicesAccountName As String = ConfigurationManager.AppSettings("accountname")
Dim mediaServicesAccountKey As String = ConfigurationManager.AppSettings("accountkey")
Dim mediaCloud As New CloudMediaContext(mediaServicesAccountName, mediaServicesAccountKey)
Dim assetOptions As New AssetCreationOptions()
Dim asset = mediaCloud.Assets.Create(Filename, assetOptions)
Dim assetFile = asset.AssetFiles.Create(Filename)
Dim accessPolicy = mediaCloud.AccessPolicies.Create(Filename, TimeSpan.FromDays(3), AccessPermissions.Write Or AccessPermissions.List)
Dim locator As ILocator
locator = mediaCloud.Locators.CreateLocator(LocatorType.Sas, asset, accessPolicy)
gSasURL = locator.BaseUri
locator.Delete()
accessPolicy.Delete()
End Sub
Thanks.
The link above is certainly not SAS. If you read the documentation for Locator here: http://msdn.microsoft.com/en-us/library/windowsazure/hh974308.aspx#create_a_locator, you will notice that BaseUri is defined as
Part of the locator that provides the store/service/container
information about the asset. (for example, Dns Host name
http://someservice.cloudapp.net)
There's another property called ContentAccessComponent which gets returned as a part of locator and that contains the SAS. So in your code this is what you would do:
uploadSasUrl = locator.BaseUri & 'File Name' & locator.ContentAccessComponent
Basically you will concatenate BaseUri, file which is being uploaded and ContentAccessComponent. Do give it a try.
Also I noticed that you're deleting the access policy once you get the locator. I think you would need to keep the access policy in place till the time blob is uploaded.
I want to parse url attribute from the XML and show image in image control (the one reffered to by the URL) in listbox from the following feed link: http://feeds.bbci.co.uk/news/rss.xml
My code is:
var ComingNewsFromUri = from rss in XElement.Parse(e.Result).Descendants("item")
select new NewsItems
{
Title = rss.Element("title").Value,
PubDate = rss.Element("pubDate").Value,
Description = rss.Element("description").Value
};
For RSS, I would recommend using SyndicationFeed and SyndicationItem....does all the parsing and converting to objects automatically and brilliantly for you.
http://ryanhayes.net/blog/how-to-build-an-rss-feed-reader-in-windows-phone-7part-i-retrieving-parsing-and-displaying-post-titles/
I have an RSS feed app on the store myself using SyndicationFeed and it is very reliable and convenient.
Here is another sample by Microsoft
http://code.msdn.microsoft.com/wpapps/RSS-Reader-Sample-1702775f