Web服务问题内容类型text / html与绑定应用程序/ soap + xml

时间:2018-01-17 12:38:16

标签: c# .net web-services adfs3.0 ws-trust

我正在使用ADFS,服务器网址为: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请求,HttpWebResponse响应,HttpChannelFactory 1 factory, WebException responseException, ChannelBinding channelBinding) at System.ServiceModel.Channels.HttpChannelFactory 1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan超时),位于System.ServiceModel.Channels.RequestChannel。 System.ServiceModel上System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan超时)的System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(消息消息,TimeSpan超时)请求(消息消息,TimeSpan超时) System.ServiceModel上的System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)中的.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan timeout) .Channels.ServiceChannelProxy.Invoke(IMessage message)在[0]处重新抛出异常:在System.Runtime.Remoting.Proxies.RealProx y.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32类型)位于System.ServiceModel.Security.WSTrustChannel.Issue(RequestSecurityToken rst,RequestSecurityTokenResponse& rstr)的System.ServiceModel.Security.IWSTrustContract.Issue(消息消息),位于System.ServiceModel.Security.WSTrustChannel.Issue(RequestSecurityToken rst) )在上面一行中的methodname(参数)抛出错误

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

请帮帮我! 提前致谢

0 个答案:

没有答案