1

I have tried Req.OptionalInputs.FieldLocatorOpeningPattern = "<<"; Req.OptionalInputs.FieldLocatorClosingPattern = ">>";

but sign is not replaced the space provided in pdf. Can you please provide a code sample for using the Soap API.

Larry K
  • 47,808
  • 15
  • 87
  • 140
Suneer P A
  • 56
  • 8
  • Please elaborate your question. – Nilambar Sharma Jun 11 '15 at 10:14
  • I am using CoSign Signature SOAP API .I need to put sign on specified location on my pdf.In CoSign Signature Local i can see that there is an option to sign on dynamic location(using field locator).I am looking for the same in CoSign Signature SOAP API. – Suneer P A Jun 11 '15 at 10:36

1 Answers1

1

Please see the code sample below for using CoSign Signature SOAP API (aka SAPIWS) with CoSign Signature Locators:

    public SAPISigFieldSettingsType[] getSigFieldLocatorsInPDF(
        string FileName,
        string UserName,
        string Password)
    {

        //Create Request object contains signature parameters
        RequestBaseType Req = new RequestBaseType();
        Req.OptionalInputs = new RequestBaseTypeOptionalInputs();

        //Here Operation Type is set: enum-field-locators
        Req.OptionalInputs.SignatureType = SignatureTypeFieldLocators;

        //Configure Create and Sign operation parameters:
        Req.OptionalInputs.ClaimedIdentity = new ClaimedIdentity();
        Req.OptionalInputs.ClaimedIdentity.Name = new NameIdentifierType();
        Req.OptionalInputs.ClaimedIdentity.Name.Value = UserName;                       //User Name
        Req.OptionalInputs.ClaimedIdentity.Name.NameQualifier = " ";                    //Domain (relevant for Active Directory environment only)
        Req.OptionalInputs.ClaimedIdentity.SupportingInfo = new CoSignAuthDataType();
        Req.OptionalInputs.ClaimedIdentity.SupportingInfo.LogonPassword = Password;     //User Password
        Req.OptionalInputs.FieldLocatorOpeningPattern = "<<";
        Req.OptionalInputs.FieldLocatorClosingPattern = ">>";

        //Set Session ID
        Req.RequestID = Guid.NewGuid().ToString();

        //Prepare the Data to be signed
        DocumentType doc1 = new DocumentType();
        DocumentTypeBase64Data b64data = new DocumentTypeBase64Data();
        Req.InputDocuments = new RequestBaseTypeInputDocuments();
        Req.InputDocuments.Items = new object[1];

        b64data.MimeType = "application/pdf";     //Can also be: application/msword, image/tiff, pplication/octet-string
        Req.OptionalInputs.ReturnPDFTailOnlySpecified = true;
        Req.OptionalInputs.ReturnPDFTailOnly = false;
        b64data.Value = ReadFile(FileName, true); //Read the file to the Bytes Array

        doc1.Item = b64data;
        Req.InputDocuments.Items[0] = doc1;

        //Call sign service
        ResponseBaseType Resp = null;

        try
        {
            // Create the Web Service client object
            DSS service = new DSS();
            service.Url = "https://prime.cosigntrial.com:8080/sapiws/dss.asmx";  //This url is constant and shouldn't be changed

            SignRequest sreq = new SignRequest();
            sreq.InputDocuments = Req.InputDocuments;
            sreq.OptionalInputs = Req.OptionalInputs;

            //Perform Signature operation
            Resp = service.DssSign(sreq);

            if (Resp.Result.ResultMajor != Success ) 
            {
                MessageBox.Show("Error: " + Resp.Result.ResultMajor + " " + 
                                            Resp.Result.ResultMinor + " " + 
                                            Resp.Result.ResultMessage.Value, "Error");
                return null;
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error");
            if (ex is WebException)
            {
                WebException we = ex as WebException;
                WebResponse webResponse = we.Response;
                if (webResponse != null)
                    MessageBox.Show(we.Response.ToString(), "Web Response");
            }
            return null;
        }


        //Handle Reply
        DssSignResult sResp = (DssSignResult) Resp;

        return Resp.OptionalOutputs.SAPISeveralSigFieldSettings;
    }
Almog G.
  • 817
  • 7
  • 11
Ari S.
  • 86
  • 3
  • Thanks Ari and Larry!.But i tried this code and am getting following error "Failed to verify user name and password" .Also checked my username and password its correct.I used the signature type operation is SignatureTypeFieldLocators ="http://arx.com/SAPIWS/DSS/1.0/signature-field-sign". – Suneer P A Jun 15 '15 at 16:26
  • The service URL pointed to a different appliance from the one you were trying to connect to. It should work fine now as it is now pointing to the CoSign trial appliance. – Almog G. Jun 17 '15 at 12:59