问题
We've implement docusign api into our application and it works fine in development and on one of our production servers, but on particular production server it fails when running the following line
var scope = new OperationContextScope(client.InnerChannel);
The exception thrown is
Error: InvalidDataContractException: Message: Type 'System.Threading.Tasks.Task`1[DocuSign.DocuSignWeb.SetSharedAccessResult]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
Here is the complete method that is called
public DocuSignResponse SendEnvelope(Envelope envelope, string templateGUID)
{
var response = new DocuSignResponse();
var client = new DSAPIServiceSoapClient("DSAPIServiceSoap", URL);
try
{
var scope = new OperationContextScope(client.InnerChannel);
{
HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers.Add("X-DocuSign-Authentication", AuthHeader);
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
if (client.InnerChannel.State != System.ServiceModel.CommunicationState.Faulted)
{
// call service - everything's fine
}
else
{
// channel faulted - re-create your client and then try again
response.Success = false;
response.ErrorMessage = "Channel has faulted!!";
return response;
}
client.Open();
EnvelopeStatus envelopeStatus;
if (!string.IsNullOrEmpty(templateGUID))
{
DocuSignWeb.EnvelopeInformation envelopeInfo = new DocuSignWeb.EnvelopeInformation();
envelopeInfo.AccountId = AccountId;
envelopeInfo.EmailBlurb = envelope.EmailBlurb;
envelopeInfo.Subject = envelope.Subject;
// Configure the inline templates
DocuSignWeb.InlineTemplate inlineTemplate = new DocuSignWeb.InlineTemplate();
inlineTemplate.Sequence = "1";
inlineTemplate.Envelope = new DocuSignWeb.Envelope();
inlineTemplate.Envelope.Recipients = envelope.Recipients;
inlineTemplate.Envelope.AccountId = AccountId;
DocuSignWeb.CompositeTemplate template = new DocuSignWeb.CompositeTemplate();
template.InlineTemplates = new DocuSignWeb.InlineTemplate[] {inlineTemplate};
DocuSignWeb.ServerTemplate serverTemplate = new DocuSignWeb.ServerTemplate();
serverTemplate.Sequence = "1";
serverTemplate.TemplateID = templateGUID;
template.ServerTemplates = new[] {serverTemplate};
template.Document = envelope.Documents[0];
envelopeStatus = client.CreateEnvelopeFromTemplatesAndForms(envelopeInfo, new[] {template}, true);
}
else
{
envelopeStatus = client.CreateAndSendEnvelope(envelope);
}
// An envelope ID indicates that it succeeded
response.Success = true;
response.ResponseRef = envelopeStatus.EnvelopeID;
// No point doing this, as it wouldn't have been signed
// Request the status of that envelope
// response.Status = client.RequestStatus(envelopeStatus.EnvelopeID);
// Used if embed option being used
response.Envelope = envelope;
response.Status = envelopeStatus;
if (client.State != CommunicationState.Faulted)
{
client.Close();
}
else
{
client.Abort();
}
}
}
catch (InvalidDataContractException err)
{
err.LogError();
response.Success = false;
response.ErrorMessage = string.Format("InvalidDataContractException: Message: {0} StackTrace: {1} AuthHeader: {2}", err.Message, err.StackTrace, AuthHeader);
}
catch (CommunicationException err)
{
err.LogError();
response.Success = false;
response.ErrorMessage = string.Format("CommunicationException: Message: {0} StackTrace: {1}", err.Message, err.StackTrace);
client.Abort();
}
catch (TimeoutException err)
{
err.LogError();
response.Success = false;
response.ErrorMessage = string.Format("TimeoutException: Message: {0} StackTrace: {1}", err.Message, err.StackTrace);
client.Abort();
}
catch (Exception err)
{
err.LogError();
response.Success = false;
response.ErrorMessage = string.Format("Exception: Message: {0} StackTrace: {1}", err.Message, err.StackTrace);
client.Abort();
}
finally
{
client = null;
}
return response;
}
At the moment i'm at a loss as to what the issue is, given the same code and database works on another machines, so at present thinking it's environmental.
Any help greatly appreciated.
回答1:
Looks like this turned out to be server issues on DocuSign side. Occasionally there are bugs and other issues that get rolled back in DocuSign's Demo sandbox environment.
来源:https://stackoverflow.com/questions/37051550/docusign-net-send-enevlope-issue-on-one-server