未指定用于在url处与联合服务进行通信的绑定

我目前正在使用ADFS作为安全令牌服务。 我想将WCF服务与ADFS联合起来。 我创建了WCF服务并使用Federation实用程序添加了ADFS的STS引用。

为了使用联合wcf服务,我创建了WPF应用程序并添加了服务引用。 我使用以下代码调用了服务api。

var client = new SecureWpfApplication.ServiceReference1.Service1Client(); Uri uri = new Uri("http://tempuri.org/"); ICredentials credentials = CredentialCache.DefaultCredentials; NetworkCredential credential = credentials.GetCredential(uri, "Basic"); client.ClientCredentials.Windows.ClientCredential = credential; client.ClientCredentials.SupportInteractive = false; client.GetData(323); 

我收到错误“未指定用于与’https:// {ADFS服务器} / adfs / services / trust / 13 / usernamemixed’的联合服务进行通信的绑定”。

怎么解决这个?

我创建了像wcf一样的服务配置

                                                    

我收到错误“未指定在’ https://adfsserver.com/adfs/services/trust/13/usernamemixed ‘上用于与联合服务通信的绑定。

在我看来,在继续使用WCF服务之前,您需要遵循更多教程和/或阅读更多网页。 如何使用WCF对于本网站而言过于宽泛,但在基本方面,您需要在配置文件中定义一个绑定元素,指定您要在WCF服务中使用联合身份validation服务。

请仔细阅读如何:在MSDN上创建WSFederationHttpBinding页面。 从链接页面:

在绑定部分中创建一个可用于与安全令牌服务通信的元素。 有关创建绑定的更多信息,请参见如何:在配置中指定服务绑定。

您还可以阅读MSDN上的(WCF)入门教程页面,以获得进一步的背景阅读。

我让它为我工作的方式是不使用通过添加服务引用生成的配置,而是以编程方式完成所有操作。 这对我有用:

 //Helper to get SAML token from STS public static SecurityToken GetSamlToken(string realm, string trustUrl, string userName, string password, string keyType, SecurityToken actAsToken = null) { var factory = new WSTrustChannelFactory( //You will need to use WindowsWSTrustBinding here I think new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential), trustUrl ); factory.TrustVersion = TrustVersion.WSTrust13; //Here you would use Windows credentials instead of username/password factory.Credentials.UserName.UserName = userName; factory.Credentials.UserName.Password = password; var rst = new RequestSecurityToken { RequestType = RequestTypes.Issue, TokenType = TokenTypes.Saml2TokenProfile11, KeyType = keyType, //I used KeyTypes.Bearer here AppliesTo = new EndpointReference(realm) }; if (actAsToken != null) { rst.ActAs = new SecurityTokenElement(actAsToken); } var token = factory.CreateChannel().Issue(rst); return token; } var token = GetSamlToken(...); var binding = new WS2007FederationHttpBinding(WSFederationHttpSecurityMode.Message); binding.Security.Message.EstablishSecurityContext = false; binding.Security.Message.IssuedKeyType = SecurityKeyType.BearerKey; var factory = new ChannelFactory(binding, new EndpointAddress(serviceEndpoint)); ChannelFactoryOperations.ConfigureChannelFactory(factory); factory.Credentials.SupportInteractive = false; factory.Credentials.UseIdentityConfiguration = true; var channel = factory.CreateChannelWithIssuedToken(token); channel.CallSomeServiceMethod();