Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net core调用wcf服务-SecurityAccessDeniedException:无法对安全令牌进行身份验证或授权_.net_Wcf_Asp.net Core 3.1 - Fatal编程技术网

.net core调用wcf服务-SecurityAccessDeniedException:无法对安全令牌进行身份验证或授权

.net core调用wcf服务-SecurityAccessDeniedException:无法对安全令牌进行身份验证或授权,.net,wcf,asp.net-core-3.1,.net,Wcf,Asp.net Core 3.1,无论.net core 3.1中的basicHttpBinding或wsHttpBinding如何,都会收到以下错误消息: SecurityAccessDeniedException: The security token could not be authenticated or authorized System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault

无论.net core 3.1中的basicHttpBinding或wsHttpBinding如何,都会收到以下错误消息:

 SecurityAccessDeniedException: The security token could not be authenticated or authorized
 System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, string action, MessageVersion version, FaultConverter faultConverter)
 System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ref ProxyRpc rpc)
 System.ServiceModel.Channels.ServiceChannel.EndCall(string action, object[] outs, IAsyncResult result)
 System.ServiceModel.Channels.ServiceChannelProxy+TaskCreator+<>c__DisplayClass1_0.<CreateGenericTask>b__0(IAsyncResult asyncResult)

我不是想要一个解决方案,而是一些关于我在这里做错了什么或者我应该尝试找出什么的指针?

绑定类型和凭据的种类应该与服务器的配置一致。
我建议您生成一个客户端代理来调用远程服务。

通过这个工具,我们可以生成一个代理,并获得与服务器配置相对应的正确配置。之后,我们可以调用该服务

ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
            var result = client.TestAsync();
            Console.WriteLine(result.Result);
由于该工具还可以在客户端生成服务契约,因此我们还可以根据
Reference.cs
文件中生成的服务配置更改调用远程服务的方式

BasicHttpBinding binding = new BasicHttpBinding();
            binding.Security.Mode = BasicHttpSecurityMode.None;
            Uri uri = new Uri("http://10.157.13.69:21011");
            ChannelFactory<IService> channelFactory = new ChannelFactory<IService>(binding, new EndpointAddress(uri));
            IService service = channelFactory.CreateChannel();
            var result1 = service.TestAsync();
            Console.WriteLine(result1.Result);
BasicHttpBinding=new BasicHttpBinding();
binding.Security.Mode=BasicHttpSecurityMode.None;
Uri=新的Uri(“http://10.157.13.69:21011");
ChannelFactory ChannelFactory=新的ChannelFactory(绑定,新的端点地址(uri));
IService服务=channelFactory.CreateChannel();
var result1=service.TestAsync();
Console.WriteLine(result1.Result);
我们应该注意的是绑定类型和安全类型应该与服务器上的一致。因此,第一件重要的事情是我们应该找出服务器配置并将其应用到客户端。
如果问题仍然存在,请随时通知我。

我将创建一个
通道工厂
,而不是从客户端获取通道工厂,以防客户端缓存任何内容:

var channelFactory = new ChannelFactory<SoapInterfaceType>(binding, remoteAddress);
channelFactory.Credentials.UserName.UserName = "";
channelFactory.Credentials.UserName.Password = "";
var channel = channelFactory.CreateChannel();
var channelFactory=新的channelFactory(绑定,远程地址);
channelFactory.Credentials.UserName.UserName=“”;
channelFactory.Credentials.UserName.Password=“”;
var channel=channelFactory.CreateChannel();

我已经生成了一个代理类,但是如何查找服务器上使用的绑定以及.net core支持的绑定/检查ServiceReference1命名空间中的Reference.cs文件。它包含代理类、服务契约、绑定类型。当我们实例化客户端代理时,这些配置将自动使用。它只接受System.ServiceModel.Channels.Binding的对象。Reference.cs文件中没有其他内容。可能会导致Reference.cs文件为空。默认情况下,Webhttpbinding创建的WCF服务不支持使用代理进行调用。该文件将不生成任何内容。webhttpbinding的服务是RESTAPI。我们需要使用HTTP库发送HTTP请求,该请求通常附带HTTP动词和请求体。请向您的服务提供商咨询更多详细信息。我们发现错误的原因是WCF服务具有WS-Policys,而其中两个策略在.NET Core中不受支持。一个是sp:encryptedsecuritytoken,另一个是sp:trust发现错误的原因是WCF服务具有WS-Policys,其中两个策略在.NET Core中不受支持。一个是sp:encryptedsecuritytoken,另一个是sp:trust@Baahubali好发现。也许你想把它贴出来作为你自己的答案,这样人们就可以很容易地找到它。是的,我还没能克服这个问题。我试图弄清楚如何手动编写一个类,以满足.NETCore中的这些策略。我的问题是:
var channelFactory = new ChannelFactory<SoapInterfaceType>(binding, remoteAddress);
channelFactory.Credentials.UserName.UserName = "";
channelFactory.Credentials.UserName.Password = "";
var channel = channelFactory.CreateChannel();