【发布时间】:2021-11-10 14:08:03
【问题描述】:
我需要帮助在 ASP.NET 5.0 Core/ASP.NET 3.1 Core (VS2019) 中配置带有基本身份验证 (http) 的 SOAP 请求。
我已经构建了一个 ASP.NET Core Web API (.NET 3.1/5.0) 项目,以便使用具有基本身份验证的 SOAP 服务。但是我的代码无法将基本身份验证数据发送到服务,当我在 VS2019 中运行项目时,我得到了这个异常:
抛出异常:System.Private.CoreLib.dll 中的“System.ServiceModel.Security.MessageSecurityException” System.Private.CoreLib.dll 中出现“System.ServiceModel.Security.MessageSecurityException”类型的异常,但未在用户代码中处理 HTTP 请求未经客户端身份验证方案“匿名”授权。从服务器收到的身份验证标头是 'Basic realm="test"'
SOAP 服务由 .NET Core“连接服务”(Microsoft WCF Web 服务参考提供者)和 WSDL 配置。
我正在尝试使用以下代码创建 http 绑定:
MyService.UpdateReq invoiceInfo = new MyService.UpdateReq();
MyService.JRPClient updateREQ = new MyService.JRPClient();
((BasicHttpBinding)updateREQ.Endpoint.Binding).Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
((BasicHttpBinding)updateREQ.Endpoint.Binding).Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
updateREQ.ClientCredentials.UserName.UserName = "username";
updateREQ.ClientCredentials.UserName.Password = "pwd";
MyService.ResponseType response = new MyService.ResponseType();
response = updateREQ.UpdateReq(invoiceInfo);
我还更改了 %PortTypeChannel 文件:
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
{
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.Security.Mode = BasicHttpSecurityMode.Transport;
result.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
result.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
return result;
但现在它失败并显示其他消息:
抛出异常:System.Private.ServiceModel.dll 中的“System.ArgumentException” System.Private.ServiceModel.dll 中出现“System.ArgumentException”类型的异常,但未在用户代码中处理 提供的 URI 方案“http”无效;预期为“https”
我用soapUI尝试了soap服务,添加了基本身份验证,它就可以工作了。
谢谢
【问题讨论】:
标签: asp.net-core wcf asp.net-web-api web-applications