Skip to content

Instantly share code, notes, and snippets.

@DominicCronin
Created February 19, 2014 09:46
Show Gist options
  • Save DominicCronin/9088961 to your computer and use it in GitHub Desktop.
Save DominicCronin/9088961 to your computer and use it in GitHub Desktop.
get-ImportExportServiceClient
function get-ImportExportServiceClient {
param(
[parameter(Mandatory=$false)]
[AllowNull()]
[ValidateSet("Service","Upload","Download")]
[string]$type="Service"
)
InitImportExport
$binding = new-object System.ServiceModel.BasicHttpBinding
$binding.MaxBufferPoolSize = [int]::MaxValue
$binding.MaxReceivedMessageSize = [int]::MaxValue
$binding.ReaderQuotas.MaxArrayLength = [int]::MaxValue
$binding.ReaderQuotas.MaxBytesPerRead = [int]::MaxValue
$binding.ReaderQuotas.MaxStringContentLength = [int]::MaxValue
$binding.ReaderQuotas.MaxNameTableCharCount = [int]::MaxValue
switch($type)
{
"Service" {
$binding.Security.Mode = [System.ServiceModel.BasicHttpSecurityMode]::TransportCredentialOnly
$binding.Security.Transport.ClientCredentialType = [System.ServiceModel.HttpClientCredentialType]::Windows
$endpoint = new-object System.ServiceModel.EndpointAddress http://localhost/webservices/ImportExportService2013.svc/basicHttp
new-object Tridion.ContentManager.ImportExport.Client.ImportExportServiceClient $binding,$endpoint
}
"Download" {
$binding.Security.Mode = [System.ServiceModel.BasicHttpSecurityMode]::TransportCredentialOnly
$binding.Security.Transport.ClientCredentialType = [System.ServiceModel.HttpClientCredentialType]::Windows
$binding.TransferMode = [ServiceModel.TransferMode]::StreamedResponse
$binding.MessageEncoding = [ServiceModel.WsMessageEncoding]::Mtom
$endpoint = new-object System.ServiceModel.EndpointAddress http://localhost/webservices/ImportExportService2013.svc/streamDownload_basicHttp
new-object Tridion.ContentManager.ImportExport.Client.ImportExportStreamDownloadClient $binding,$endpoint
}
"Upload" {
$binding.Security.Mode = [System.ServiceModel.BasicHttpSecurityMode]::None
$binding.TransferMode = [ServiceModel.TransferMode]::StreamedRequest
$binding.MessageEncoding = [ServiceModel.WsMessageEncoding]::Mtom
$endpoint = new-object System.ServiceModel.EndpointAddress http://localhost/webservices/ImportExportService2013.svc/streamUpload_basicHttp
new-object Tridion.ContentManager.ImportExport.Client.ImportExportStreamUploadClient $binding,$endpoint
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment