/// <summary>
/// Store local file as object on IMiS/ARC Storage Server.
/// </summary>
/// <param name="client">
/// An IMiS/Storage Connector SOAP service port client.
/// </param>
/// <param name="storage">
/// An IMiS/ARChive storage alias.
/// </param>
/// <param name="contentType">
/// The content type of the local file to be stored.
/// </param>
/// <param name="filePath">
/// The file path of the local file to be stored.
/// </param>
/// <returns>
/// The IMiS/ARC Storage Server object identifier.
/// </returns>
static string StoreObjectToIMiSARC(ServiceReference1.ServicePortClient client,
string storage, string contentType, string filePath)
{
// Store operation parameters
ServiceReference1.StoreObjectRequest storeRequest = new StoreObjectRequest();
// Profile into which this object should be saved
storeRequest.Storage = storage;
// TransferDisposition describes how objects will be transferred
// across the wire.
// TRANSFER_AS_STREAM: Transfer object body as binary stream in
// Data parameter of the Request/Response message
// (conforms to WS-I Basic Profile 1.0)
// TRANSFER_AS_ATTACHMENT: Transfer object as attachment
// conforming to WS-I Attachments Profile 1.0
storeRequest.TransferDisposition = ServiceReference1.ObjectTransferDisposition.TRANSFER_AS_STREAM;
// Describes the content of the stored object
storeRequest.ContentType = contentType;
// Read input file
FileStream fileStream = new FileStream(filePath, FileMode.Open);
storeRequest.Data = new byte[fileStream.Length];
fileStream.Read(storeRequest.Data, 0, storeRequest.Data.Length);
fileStream.Close();
// Execute the command. If call succeeds result holds unique
// object ID which need to be saved for future references
ServiceReference1.StoreObjectResponse storeResult = client.StoreObject(storeRequest);
// Response's ObjectID property holds new object unique identifier used
// for object retrieval
return storeResult.ObjectID;
}
/// <summary>
/// Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication.
/// </summary>
/// <param name="client">
/// An IMiS/Storage Connector SOAP service port client.
/// </param>
/// <param name="certificate">
/// The certificate used to authenticate the remote party.
/// </param>
/// <param name="chain">
/// The chain of certificate authorities associated with the remote certificate.
/// </param>
/// <param name="policyErrors">
/// One or more errors associated with the remote certificate.
/// </param>
/// <returns>
/// <c>True</c> if the specified certificate is accepted for authentication; otherwise <c>False</c>.
/// </returns>
static bool ValidateRemoteCertificate(object sender, X509Certificate certificate,
X509Chain chain, SslPolicyErrors policyErrors)
{
// Validate server certificate is necessary!
return true;
}
/// <summary>
/// Stores object to IMiS/ARChive server using Digest authentication over SSL.
/// </summary>
static void SSLDigestAuthentication()
{
try
{
// Assign server certificate validation callback
ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
// Create service port client instance
ServiceReference1.ServicePortClient client = new ServiceReference1.ServicePortClient("IMiSStorageConnectorSOAPService_SSL_Digest");
// Create client credentials
client.ClientCredentials.HttpDigest.ClientCredential = new NetworkCredential(USERNAME, PASSWORD);
client.ClientCredentials.HttpDigest.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
// Store object to IMiS/ARChive server
StoreObjectToIMiSARC(client, STORAGE, CONTENTTYPE, FILEPATH);
}
catch (Exception ex)
{
Console.Out.WriteLine("ErrorMessage = {0}", ex.Message);
}
} |