Created
March 8, 2017 12:12
-
-
Save pmedcraft/997cb2d0d9c23bace20007fdb8c0d223 to your computer and use it in GitHub Desktop.
C# helper class for connecting to SDL Media Manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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