首页 > 解决方案 > 通过尝试从肥皂服务检索数据,HTTP 请求未经授权

问题描述

当我尝试从我的 asp.net core 2.2 控制器中的 BC365 soap 服务检索数据时,我收到以下错误:

HTTP 请求未经客户端身份验证方案“匿名”授权。从服务器收到的身份验证标头是“协商”。

有趣的是: 如果我在本地调试项目,它可以使用以下代码按预期工作

var binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.MaxBufferSize = int.MaxValue;
binding.MaxReceivedMessageSize = int.MaxValue;
var endpointAddress = new System.ServiceModel.EndpointAddress(this.soapBaseUrl + "Page/WEB_Item");
var itemPortClient = new WEB_Item_PortClient(binding, endpointAddress);
itemPortClient.ClientCredentials.UserName.UserName = this.soapUserName;
itemPortClient.ClientCredentials.UserName.Password = this.soapPassword;
return itemPortClient;

但是每当我在 IIS 上发布它时,它都没有按预期工作(我已经在远程和本地机器上尝试过)。我已按照https://stackify.com/how-to-deploy-asp-net-core-to-iis/上的说明部署我的 asp.net 核心应用程序。

我的基础设施项目 .csproj 文件的内容如下所示:

<Project Sdk="Microsoft.NET.Sdk">    
  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>    
  <ItemGroup>
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.5.3"/>
    <PackageReference Include="System.ServiceModel.Http" Version="4.5.3" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.5.3"/>
    <PackageReference Include="System.ServiceModel.Security" Version="4.5.3" />
  </ItemGroup>    
  <ItemGroup>
    <ProjectReference Include="..\BakWebshop.Core\BakWebshop.Core.csproj" />
  </ItemGroup>    
  <ItemGroup>
    <WCFMetadata Include="Connected Services" />
  </ItemGroup>    
</Project>

如果有人知道可能有什么问题或我可以检查什么,我现在有点卡在这里。任何帮助深表感谢。

标签: c#soapasp.net-core-2.2

解决方案


问题与用于启动soap 请求的不同用户有关,使用2.2 .net 核心。该请求是使用手动定义的凭据发出的,但不知何故,在框架触发请求时,它们并没有被考虑在内。

从 VS2019 运行,本地用户被使用并且能够连接(在soap端点上被允许)。

使用应用程序池标识在具有应用程序池的 IIS 上运行无法正常工作,因为不知何故,没有使用用于 soap 请求的指定用户凭据,而是使用了 ApplicationPoolIdentity - 未授予对 soap 端点的访问权限。

解决方法是为 iis 池使用用户定义的帐户。看起来与https://stackoverflow.com/a/10311823如何让 HttpClient 与请求一起传递凭据有关?


推荐阅读