Skip to content

Instantly share code, notes, and snippets.

@pmedcraft
Created March 8, 2017 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmedcraft/997cb2d0d9c23bace20007fdb8c0d223 to your computer and use it in GitHub Desktop.
Save pmedcraft/997cb2d0d9c23bace20007fdb8c0d223 to your computer and use it in GitHub Desktop.
C# helper class for connecting to SDL Media Manager
using Migration.MediaManager;
using System.ServiceModel;
using System.IdentityModel.Tokens;
using System.Configuration;
using System.ServiceModel.Security;
using System.IdentityModel.Protocols.WSTrust;
namespace Migration.Helpers
{
public class MediaManagerHelper
{
private static SecurityToken RequestSecurityToken()
{
WSTrustChannelFactory factory = new WSTrustChannelFactory(new WS2007HttpBinding("ws2007HttpsBindingConfiguration"),
new EndpointAddress(ConfigurationManager.AppSettings["IssuerName"]))
{
TrustVersion = TrustVersion.WSTrust13
};
RequestSecurityToken rst = new RequestSecurityToken
{
RequestType = RequestTypes.Issue,
KeyType = KeyTypes.Symmetric,
AppliesTo = new EndpointReference(ConfigurationManager.AppSettings["MediaManagerWebServiceAddress"]),
DelegateTo = new SecurityTokenElement(new UserNameSecurityToken(@"API\UploadToolUser", ""))
};
RequestSecurityTokenResponse resp;
return factory.CreateChannel().Issue(rst, out resp);
}
private static IMediaManager2011 GetClient(SecurityToken token)
{
var factory = new ChannelFactory<IMediaManager2011>("FederationEndpointHttps");
return factory.CreateChannelWithIssuedToken(token);
}
public static IMediaManager2011 GetMediaManagerClient()
{
SecurityToken token = RequestSecurityToken();
return GetClient(token);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment