我有一个第三方WSDL服务,我需要集成在一个.NET核心2.1webapp中。
我通过“”>“”添加了该服务。
我有一些实用工具类,它像这样配置服务:
ServiceClient servicePort = new ServiceClient();
servicePort.ClientCredentials.UserName.UserName = USERNAME;
servicePort.ClientCredentials.UserName.Password = PASSWORD;
setupHttpHeader(servicePort.InnerChannel );哪里
public static void setupHttpHeader( IClientChannel serviceChannel )
{
using (new OperationContextScope( serviceChannel ))
{
// Add a HTTP Header to an outgoing request
HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
requestMessage.Headers["Authorization"] = "Basic " + System.Convert.ToBase64String(Encoding.UTF8.GetBytes(USERNAME + ":" + PASSWORD));
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
}
}现在,当我试图调用控制器中的端点时,我得到了以下异常:
System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'basic realm="appbox object-model"'. 在一个旧的用于连接第三方服务的.NET Framework4.0示例中,有一个app.config为绑定提供了一些配置。他们看起来是这样的:
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security> 我需要在我的项目中添加什么才能让这个项目工作呢?
发布于 2018-12-05 10:46:15
在这个问题的评论中发现了该溶液。
在生成的代码的GetBindingForEndpoint部分中,需要如下所示:
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.Transport);
result.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Basic;在我的例子中,我需要TransportCredentialOnly,因为端点是http而不是https。
https://stackoverflow.com/questions/53615242
复制相似问题