This file contains hidden or 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); | |
} | |
} | |
} |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<configuration> | |
<appSettings> | |
<add key="IssuerName" value="http://localhost:89/IWSTrust13" /> | |
<add key="MediaManagerWebServiceAddress" value="https://TENANTNAME.sdlmedia.com/WebServices/MediaManager2011.svc" /> | |
<add key="ClientSettingsProvider.ServiceUri" value="" /> | |
</appSettings> | |
<system.serviceModel> | |
<bindings> | |
<ws2007FederationHttpBinding> | |
<binding name="FederationEndpointHttps" transactionFlow="true" sendTimeout="00:05:00" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> | |
<security mode="TransportWithMessageCredential"> | |
<message> | |
<issuer address="http://localhost:89/IWSTrust13" binding="ws2007HttpBinding" bindingConfiguration="ws2007HttpsBindingConfiguration"> | |
<identity> | |
<servicePrincipalName value="host/localhost" /> | |
</identity> | |
</issuer> | |
<issuerMetadata address="http://localhost:89/IWSTrust13/?mex" /> | |
<tokenRequestParameters> | |
<trust:SecondaryParameters xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512"> | |
<trust:KeyType xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://docs.oasis-open.org/ws-sx/ws-trust/200512/SymmetricKey</trust:KeyType> | |
<trust:KeySize xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">256</trust:KeySize> | |
<trust:Claims Dialect="http://schemas.xmlsoap.org/ws/2005/05/identity" xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512"> | |
<wsid:ClaimType Uri="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" xmlns:wsid="http://schemas.xmlsoap.org/ws/2005/05/identity" /> | |
<wsid:ClaimType Uri="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname" xmlns:wsid="http://schemas.xmlsoap.org/ws/2005/05/identity" /> | |
</trust:Claims> | |
<trust:KeyWrapAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p</trust:KeyWrapAlgorithm> | |
<trust:EncryptWith xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/04/xmlenc#aes256-cbc</trust:EncryptWith> | |
<trust:SignWith xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2000/09/xmldsig#hmac-sha1</trust:SignWith> | |
<trust:CanonicalizationAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/10/xml-exc-c14n#</trust:CanonicalizationAlgorithm> | |
<trust:EncryptionAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/04/xmlenc#aes256-cbc</trust:EncryptionAlgorithm> | |
</trust:SecondaryParameters> | |
</tokenRequestParameters> | |
</message> | |
</security> | |
</binding> | |
</ws2007FederationHttpBinding> | |
<ws2007HttpBinding> | |
<binding name="ws2007HttpsBindingConfiguration" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> | |
<readerQuotas maxStringContentLength="2147483646" maxArrayLength="2147483646" /> | |
<security mode="Message"> | |
<message establishSecurityContext="false" /> | |
</security> | |
</binding> | |
</ws2007HttpBinding> | |
</bindings> | |
<client> | |
<!-- Adding the Media Manager endpoint --> | |
<endpoint address="https://TENANTNAME.sdlmedia.com/WebServices/MediaManager2011.svc" binding="ws2007FederationHttpBinding" bindingConfiguration="FederationEndpointHttps" contract="MediaManager.IMediaManager2011" name="FederationEndpointHttps" /> | |
</client> | |
</system.serviceModel> | |
</configuration> |
Hello Philip, Thanks for the code! I am getting the below exception while connecting to Media manager with the above code
ReplyDeleteSystem.ServiceModel.Security.MessageSecurityException: 'An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.'
Stack trace:
Server stack trace:
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout)
at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout)
at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout)
at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.LayeredChannel`1.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at MMproxy.MediaManager2011WebService.IMediaManager2011.GetRootList(GetListResultLevel resultLevel)
at TestConsoleApp.Program.Main(String[] args)
Any pointers regarding what could be going wrong?