0

我正在尝试使用 WCF 使用 Intranet Web 服务。我通过VS2008 中的添加服务引用功能添加了对服务的引用。这样做时,系统提示我输入网络凭据以访问我提供的服务,并添加了服务参考。

然后,我编写了一些我预计会失败的代码,因为它没有与服务调用一起传递凭据:

FooServiceClient proxy = new FooServiceClient();
bool isValid = proxy.ValidateBar(baz);

当我使用此代码时,我收到异常:
HTTP 请求未经授权,客户端身份验证方案“协商”。
从服务器收到的身份验证标头是“Basic realm="Kerberos"”。

这是我在使用以下两个代码示例中的任何一个时收到的相同错误。

FooServiceClient proxy = new FooServiceClient();
proxy.ClientCredentials.UserName.UserName = "USERNAME";
proxy.ClientCredentials.UserName.Password = "PASSWORD";
bool isValid = proxy.ValidateBar(baz);

或者

FooServiceClient proxy = new FooServiceClient();

NetworkCredential creds = new NetworkCredential("USERNAME", "PASSWORD");

proxy.ClientCredentials.Windows.AllowedImpersonationLevel =
  TokenImpersonationLevel.Identification;
proxy.ClientCredentials.Windows.AllowNtlm = false;
proxy.ClientCredentials.Windows.ClientCredential = creds;

bool isValid = proxy.ValidateBar(baz);

我的直觉告诉我,我的安全模式配置不正确。根据服务器管理器的说法,我尝试绑定的端点是通过 SSL 查找基本 Http 凭据。在阅读了WCF-BasicHttp 传输属性之后,我相信我应该使用这个配置:

<security mode="Transport">
  <transport clientCredentialType="Windows" />
  <message clientCredentialType="UserName" algorithmSuite="Default" />
</security>

不幸的是,我继续收到同样的错误。

同样,我确信我的麻烦与我的配置问题有关,因为我以前在其他项目中使用过时的Add Web Reference使用此服务。

4

3 回答 3

2

您必须真正了解另一端的端点是在什么下配置的。如果它是自托管并在 SSL 下运行,那么它应该是Transport,但如果它在带有 SSL 的 IIS 下运行,那么它可能是TransportWithMessageCredentials并且传输凭据可能是“无”。

让它正确绑定是非常棘手的。

至于你得到的异常

提供的 URI 方案“https”无效;预期的“http”。参数名称:

当您使用TransportCredentialOnly时,您必须使用 HTTP 绑定而不是 HTTPS,而且我确信您没有将端点地址更改为 HTTP,因为这不是服务引用。

于 2009-12-16T06:08:11.740 回答
1

您在 Intranet 方案中使用什么绑定?推荐的最佳实践是具有传输安全性和 Windows 凭据的 NetTCP(假设您的所有呼叫者都是在您的公司 Active Directory 中拥有帐户的 Intranet 客户端)

这将避免任何 http/https 混乱。

但是,要托管 netTcp,您需要 WAS(Windows Process Activation Server),它是 IIS7 的一部分,并且只能在 Windows Server 2008(Vista Server)或 2008 R2(Win7 Server)上运行。或者您需要自己在 NT 服务中托管您的服务。

很多信息仍然缺失!请相应地更新您的问题。谢谢!

于 2009-12-16T06:25:21.643 回答
0

下面的 WCF绑定配置最终成为解决方案。

<security mode="Transport">
  <transport clientCredentialType="Basic" proxyCredentialType="None"
     realm="" />
  <message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
于 2009-12-22T00:36:08.823 回答