basquang™ on clouds

November 10, 2015

Secure your WCF Web Services resource references

Filed under: Digital Signature,WCF — basquang @ 3:52 PM

You want to secure your WCF web services, you want to sign digital signature on your web service here are some good references

[MSDN]: Using Message Contracts

[MSDN]How to: Set the ProtectionLevel Property

[VS Magazine] Security Considerations and Best Practices for WCF 4 Apps

[MSDN] Message Security with a Certificate Client

[MSDN] Message Security Certificate

[CodeProject] WCF Service Method Level Security using Message Contract


November 15, 2010

Develop a File IO ActiveX control in Microsoft .NET

Filed under: ActiveX,Digital Signature,Microsoft Technology — basquang @ 4:39 PM


1. Use this guide to create your own ActiveX control

Writing an ActiveX Control in .NET

2. Design your ActiveX as picture bellow:


3. Use following code behind

namespace FileIOActiveXControl
    public partial class WriteToClientControl : UserControl
        public WriteToClientControl()

        private void btnWrite_Click(object sender, EventArgs e)
            WriteLog(@"c:\temp\log.txt", txtUserInput.Text);

        public void WriteLog(string fileName, string content)
                StreamWriter log = new StreamWriter(fileName, true);
            catch (Exception ex)

3. Create TestActiveX.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
Please note that you MUST load this HTML document from your local IIS, or from a TRUSTED SITE or the control will not load properly on the page due to security policy.
To fix this:<br>
<li>copy the HTM file and the DLL into your c:\inetpub\wwwroot folder (or applicable IIS root directory)
<li>load the document in your browser with the url:  http://localhost/TestActiveX.htm
	 <OBJECT id="fileIOActiveX" name="fileIOActiveX" classid="http:FileIOActiveXControl.dll#FileIOActiveXControl.WriteToClientControl" width="450" height="100" VIEWASTEXT>


1. Copy FileIOActiveXControl.dll and TestActiveX.htm to the same folder

2. Go to IIS to create a new web site and point to that folder

3. Use another computer to test your control.

If you control cannot load to page like picture bellow.


a. Try to add the site to Trusted Zone in IE

b. Make sure .dll and .htm in the same folder

If your control is loaded correctly, you will see:


4. Enter some text to the textbox then click Write To File button. You may see:

“Request for the permission of type ‘System.Security.Permissions.FileIOPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.”


To fix this. You have to configure Code Access Security for Microsoft .NET on client. Run following command to fix this issue.

“C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\caspol.exe -quiet -machine -chggroup Trusted_Zone FullTrust”


And  (MANDATORY if your client is running OS 64 bit)

“C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\caspol.exe -quiet -machine -chggroup Trusted_Zone FullTrust”


5. Stop IE –> reload the test page –> input some text –> click “Write To File” button again now. There will not have any error message appear. Check the log file from C:\temp\log.txt


November 5, 2010

Add Digital Signature to a PDF programmatically using Adobe SDK and Microsoft .NET

Filed under: Digital Signature,PDF — basquang @ 11:18 AM


– Adobe Professional Installed

– Adobe SDK downloaded

– Microsoft Visual Studio

– Valid Certificate file (.pfx). It means the .pfx file not yet expired.

Setup environment:

– Copy sdkAddSignature.js from SDK to Acrobat\Javascripts folder

– Optional: Create Your Own Test Certificate

Code C#

Type AcrobatCAcroAppType;
            AcrobatCAcroAppType = Type.GetTypeFromProgID("");
            Acrobat.CAcroApp gapp = (Acrobat.CAcroApp)Activator.CreateInstance(AcrobatCAcroAppType);

            Type AcrobatPDDocType;
            AcrobatPDDocType = Type.GetTypeFromProgID("AcroExch.PDDoc");
            Acrobat.CAcroPDDoc gpddoc = (Acrobat.CAcroPDDoc)Activator.CreateInstance(AcrobatPDDocType);

            object jso;

            if (gpddoc.Open("d:\\temp\\s.pdf"))
                jso = gpddoc.GetJSObject();
                object[] param = new object[1];

                param[0] = "c:\\CATest.pfx";

                object con = jso.GetType().InvokeMember("SetUserDigitalIDPath",
                BindingFlags.InvokeMethod, null, jso, param);

                param[0] = "testpassword";
                con = jso.GetType().InvokeMember("SetUserPassword",
                BindingFlags.InvokeMethod, null, jso, param);                    
                param[0] = jso;

                con = jso.GetType().InvokeMember("AddSignature",
                BindingFlags.InvokeMethod, null, jso, param);            

Code VB:

Dim gapp As Acrobat.CAcroApp
    Dim gpddoc As Acrobat.CAcroPDDoc
    Dim jso As Object
    gapp = CreateObject("")
    gpddoc = CreateObject("acroexch.pddoc")

    If gpddoc.Open("d:\temp\s.pdf") Then
      jso = gpddoc.GetJSObject()
    End If

Create a free website or blog at