2015-06-11 31 views
1

我试过 Req.OptionalInputs.FieldLocatorOpeningPattern =“< <”; Req.OptionalInputs.FieldLocatorClosingPattern =“>>”;Can Field定位符可与CoSign Signature Soap API一起使用C#

但符号不会被pdf中提供的空间替换。您能否提供一个使用Soap API的代码示例。

+0

请详细说明你的问题。 – Nilambar

+0

我正在使用CoSign签名SOAP API。我需要在我的pdf上的指定位置上签名。CoSign签名本地我可以看到有一个选项在动态位置上签名(使用字段定位器)。我正在寻找相同的在CoSign签名SOAP API中。 –

回答

1

请参阅下面的使用余弦签名SOAP API(又名SAPIWS)与余弦签名定位器的代码示例:

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; 
    } 
+0

谢谢阿里和拉里!但我试过这段代码,并且出现以下错误“无法验证用户名和密码”。也检查了我的用户名和密码的正确性。我使用的签名类型操作是SignatureTypeFieldLocators =“http:// arx.com/SAPIWS/DSS/1.0/signature-field-sign”。 –

+0

指向与您尝试连接的设备不同的其他设备的服务URL。它现在应该正常工作,因为它现在指向了CoSign试用设备。 –

+0

感谢Almog.Its工作.... –

相关问题