HTTP 状态 401:从 ExtendedPSI 调用时未经授权

发布于 2024-09-26 12:36:53 字数 1297 浏览 6 评论 0原文

我目前正在尝试开发一个 ExtendedPSI Web 服务,该服务又调用许多现有的 PSI Web 服务。问题是我收到错误

System.Net.WebException:请求失败,HTTP 状态为 401:未经授权。

当我尝试使用我创建的 ExtendedPSI 访问现有 PSI 服务时。

如果我使用以下代码片段对 ExtendedPSI 中的凭据进行硬编码,我就可以让该服务正常工作:

resWS.Credentials = new NetworkCredential("userName", "userPass", "domain");

但当我使用时则不行:(

resWS.Credentials = CredentialCache.DefaultCredentials;

我尝试过 CredentialCache.DefaultNetworkCredentials,但读到这无法通过 HTTP 或 FTP 工作)

我读过很多帖子在客户端 web.config 或调用 Web 应用程序的虚拟中提供诸如启用 Windows 身份验证和删除匿名访问等建议,但是我使用 SoapUI 来调用 ExtendedPSI 服务,因为最终解决方案将由 ESB 平台调用(即 SAP PI)。

但是使用 SoapUI,我通过在 SoapUI 界面中提供登录详细信息,成功地依次调用了每个现有的 PSI 服务(在我的 ExtendedPSI 服务中调用的 Web 服务),因此我知道只要我可以传递凭据,现有的服务就可以工作但当它们是空的 使用CredentialCache.DefaultCredentials

希望这对某人有意义(这是我第一次尝试网络服务,所以如果它有点含糊,我深表歉意)。我真的不想在我的服务中硬编码登录详细信息,所以我希望有人以前遇到过这个问题,并且有一个我可以使用的解决方案...

我需要的信息是否由 HttpContext 保存?我也许可以传递一个加密令牌(刚刚到达这里:)?或者我是否需要通用用户来访问这些现有的 PSI Web 服务?

仅供参考:我遵循了文章 http://msdn.microsoft.com/en- us/library/bb428837.aspx(我已进一步扩展以调用现有的 PSI),但它假设某种 MS.NET 客户端调用该服务。

预先感谢...

问候, 格子呢博诺

I am currently trying to develop a ExtendedPSI Web service which in turn calls a number of existing PSI Web services. The trouble is I recieve the error

System.Net.WebException: The request failed with HTTP status 401: Unauthorized.

when I try to access the existing PSI services from with the ExtendedPSI I have created.

I can get the service to work if I hardcode the Credentials in my ExtendedPSI using the following snippet:

resWS.Credentials = new NetworkCredential("userName", "userPass", "domain");

but not when I use:

resWS.Credentials = CredentialCache.DefaultCredentials;

(i have tried CredentialCache.DefaultNetworkCredentials but read this doesn't work thru HTTP or FTP)

I have read numerous posts with suggestions such as enabling Windows Authentication and removing anonymous access etc. either in the client web.config or on the virtual of the calling webapp however I am using SoapUI to call the ExtendedPSI service as the final solution will be called by an ESB platform (namely SAP PI).

But using SoapUI I have managed to call each of the existing PSI services (web services called in my ExtendedPSI service) in turn by supplying my login details in the SoapUI interface so I know the existing services work as long as I can pass on the credentials but they are empty when
using CredentialCache.DefaultCredentials.

Hope this makes sense to someone (this is my first attempt at web services so I appologise if its a little vague). I don't really want to hardcode logon details within my service so I hope someone has came across this before and has a solution I can use...

Is the information I need held with the HttpContext? A encrypted token I can pass maybe (just reaching here :)? Or will I need a generic user to access these existing PSI web services?

FYI: I followed the article http://msdn.microsoft.com/en-us/library/bb428837.aspx (which i've extended further to call existing PSI's) but it assumes some sort of MS.NET client calling the service.

Thanks in advance...

Regards,
TartanBono

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱你不解释 2024-10-03 12:36:53

您应该像这样更改应用程序的web.config。只需覆盖绑定节点中的安全节点即可:

<binding name="WssInteropSoap">
  <security mode="TransportCredentialOnly">
    <transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm"
        realm="" />
    <message clientCredentialType="UserName" algorithmSuite="Default" />
  </security>
</binding>

现在您可以在没有特殊帐户(从 Windows 传递)的情况下进行身份验证,或者使用此代码,您可以指定一个帐户:

//credential impersonation (just if you changed your binding settings)
projectSvc.ClientCredentials.Windows.ClientCredential = new NetworkCredential("username", "password", "domain");
projectSvc.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

我希望它会有所帮助:)

我还写了一篇关于设置 PSI 连接的博客文章: 通过 PSI 阅读 Project Server 2010 CustomFields

You should change the web.config of your application like this. Just overwrite the security node in the binding node:

<binding name="WssInteropSoap">
  <security mode="TransportCredentialOnly">
    <transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm"
        realm="" />
    <message clientCredentialType="UserName" algorithmSuite="Default" />
  </security>
</binding>

Now you can authenticate without a special account (passthrough from windows) or with this code, you can specify an account:

//credential impersonation (just if you changed your binding settings)
projectSvc.ClientCredentials.Windows.ClientCredential = new NetworkCredential("username", "password", "domain");
projectSvc.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

I hope it will help :)

I've also written a blog entry for setting up a connection to the PSI: Read Project Server 2010 CustomFields over PSI

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文