C#.NET Core SOAP客户端基本验证标头未设置
我有一个从WSDL文件生成的客户端,并在.NET Core 3.1项目中使用它。我无法通过 clientcredentials
和 basichttp(s)绑定
设置授权标头。我用钩宾查看了我的要求。这是我的代码:
BasicHttpsBinding binding= new BasicHttpsBinding();
//for http
//binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
EndpointAddress endpoint = new EndpointAddress("https://hookb.in/...");
var soapClient = new RandomServiceClient(binding, endpoint);
soapClient.ClientCredentials.UserName.UserName = "user";
soapClient.ClientCredentials.UserName.Password = "bla";
soapClient.CallServiceMethod(new Request { Foo = "Bar" });
我已经尝试使用其他绑定,例如 wshtpbinding
,例如Microsoft文档建议: https://learn.microsoft.com/en-us/dotnet/dotnet/framework/wcf/wcf/wcf/feature-deture-details/feature-details/feature-details/transport-security-security-security-security-security-security-security-security-security-security-security-security-regin-使用基本认证
我在做什么错?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢: https://stackoverflow.com/a/a/60714907/9124424
我找到了一个解决方案,但我仍然想知道为什么我的问题中的代码不起作用,
因此您需要添加
iclientMessageInSpector
和iendpointBehavior
,然后可以添加此
iendpointbehavior
toendpoint
在客户端实例中Thanks to: https://stackoverflow.com/a/60714907/9124424
I found a solution, but i still wonder why the code in my question does not work
So you need to add an
IClientMessageInspector
and anIEndpointBehavior
And then you can add this
IEndpointBehavior
to theEndpoint
in the client instance对我来说,Stutje的解决方案非常完美,除了:
binding.security.transport.clientcredentialType = httpclientcredentialtype.basic; basic;
,否则它要求直接设置凭据。binding.security.mode = basichttpsecuritymode.transport;
用于使用httpsFor me Stutje's solution works perfect, except:
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
, otherwise it asking to set credentials directly.binding.Security.Mode = BasicHttpSecurityMode.Transport;
to use https