2

我正在使用 ADFS,服务器 URL 是:https://domainname/adfs/ls

当我使用 WSTrust 技巧在我的 .net 应用程序(框架 4.6)中使用它时,通过在解决方案中添加带有以下代码片段的 asmx 文件

var stsEndpoint = ConfigurationManager.AppSettings["EndPoint"];
        var relayPartyUri = ConfigurationManager.AppSettings["RelayPartyUri"];
        EndpointAddress epoint = new EndpointAddress(stsEndpoint);
        var factory =
            new WSTrustChannelFactory(new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential),
                epoint)
            { TrustVersion = TrustVersion.WSTrust13 };
        if (factory.Credentials != null)
        {
            factory.Credentials.UserName.UserName = @"systemdomain\" + userName;
            factory.Credentials.UserName.Password = password;
        }
        var rst = new RequestSecurityToken
        {
            RequestType = WSTrust13Constants.RequestTypes.Issue,
            AppliesTo = new EndpointReference(relayPartyUri),
            KeyType = WSTrust13Constants.KeyTypes.Bearer
        };
        var channel = factory.CreateChannel();
        var token = channel.Issue(rst);
        var genericToken = token as GenericXmlSecurityToken;

现在每次我运行应用程序时,它都会在行显示以下错误消息

var token = channel.Issue(rst);

内容类型 text/html;响应消息的 charset=utf-8 与绑定的内容类型不匹配 (application/soap+xml; charset=utf-8)。如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。响应的前 1024 个字节是:'

堆栈跟踪:

服务器堆栈跟踪:在 System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory1 factory, WebException responseException, ChannelBinding channelBinding) at System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) 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) 在 [0] 处重新抛出异常:在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage( IMessage 请求消息,IMessage retMsg) 在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 类型) 在 System.ServiceModel.Security.IWSTrustContract.Issue(Message message) 在 System.ServiceModel.Security.WSTrustChannel.Issue(RequestSecurityToken rst, RequestSecurityTokenResponse& rstr) at System.ServiceModel.Security.WSTrustChannel.Issue(RequestSecurityToken rst) at methodname(parameters) 在上面的行中抛出错误上述行中方法名称(参数)处的问题(RequestSecurityToken rst)会引发错误上述行中方法名称(参数)处的问题(RequestSecurityToken rst)会引发错误

我不知道在哪里检查这个错误,我确实有服务器访问 adfs url 也不是从 IIS 托管的。

请帮我!提前致谢

4

0 回答 0