在带有身份验证的 MonoTouch 中使用 WCF 服务

发布于 2024-11-19 14:34:18 字数 778 浏览 1 评论 0原文

我正在使用由 slsvcutil 生成的 Silverlight 工具包版本 4 生成的 WCF 服务客户端。我也尝试过版本 3,但遇到了同样的问题。当我使用在没有用户凭据的 http 上运行的客户端实例时,它运行时不会出现问题。但我需要切换到 https 以获取高效服务器,并发送为我的应用程序硬编码的用户凭据。我使用以下代码:

        var binding = new BasicHttpBinding (BasicHttpSecurityMode.TransportCredentialOnly);         
        var endpoint = new EndpointAddress (AppSettings.FlareEndPoint);
        _service = new TopicAnalystAPIClient(binding, endpoint);
        _service.ClientCredentials.UserName.UserName = "xxx";
        _service.ClientCredentials.UserName.Password =  "xxx";

当我在该服务上调用指向 http 且无需身份验证的方法时,它可以工作。当我使用带有凭据的 http/https 代码时,我收到“处理 Web 请求时出错:状态代码 401(未经授权):未经授权”异常。我已检查凭据是否正确,我可以在浏览器中打开服务引用。我还尝试了 http/https 和 SecurityMode 值的几种组合。我还在四个不同的服务器上尝试过,总是得到相同的结果。

可能是什么问题?

I am using a WCF service client generated by slsvcutil form Silverlight toolkit version 4. I've also tried version 3 with the same problems. When I use a client instance running on http with no user credentials it runs without problems. But I need to switch to https for productive servers and send user credentials that are hardcoded for my application. I use the following code for that:

        var binding = new BasicHttpBinding (BasicHttpSecurityMode.TransportCredentialOnly);         
        var endpoint = new EndpointAddress (AppSettings.FlareEndPoint);
        _service = new TopicAnalystAPIClient(binding, endpoint);
        _service.ClientCredentials.UserName.UserName = "xxx";
        _service.ClientCredentials.UserName.Password =  "xxx";

When I call a method on that service pointing to http with no authentication it works. When I use the this code against http/https with the credential I get "There was an error on processing web request: Status code 401(Unauthorized): Unauthorized" exception. I've checked that the credentials are correct, I am able to open the service reference in my browser. I've also tried several combinations of http/https and SecurityMode value. I've also tried it on four different servers always with the same result.

What can be the problem?

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

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

发布评论

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

评论(1

过期以后 2024-11-26 14:34:18

许多排列都是可能的。 BasicHttpSecurityMode.TransportCredentialOnly 应该可以在没有使用 HTTP 本身的 SSL [1] 的情况下使用。这意味着服务器将向客户端发送一种(或多种)身份验证方法(例如 basic、digest、ntlm),并且 Mono(包括 MonoTouch)应该为其中大多数方法提供支持。

链接器(如果使用)可能会删除其中之一。在这种情况下,您可以尝试在不链接的情况下构建和测试(或跳过 System.Net.dll 的链接)。

也有可能不支持服务器坚持的身份验证方法。您可以通过运行网络跟踪(例如,wireshark)来找到使用了哪一个,或者,它可能会在服务器日志中显示更多详细信息(以及 401 错误)。

[1] http:// msdn.microsoft.com/en-us/library/system.servicemodel.basichttpsecuritymode%28v=vs.95%29.aspx

A lot of permutations are possible. BasicHttpSecurityMode.TransportCredentialOnly should be usable without SSL [1] using HTTP itself. This means the server will send one (or more) authentication method(s) to the client (e.g. basic, digest, ntlm) and Mono (including MonoTouch) should be providing support for the most of them.

It is possible that the linker (if used) removes one of them. In that case you could try building and testing without linking (or skip linking of System.Net.dll).

It's also possible that the authentication method that the serve insist on is not supported. You could find which one is used by running a network trace (e.g. wireshark) or, maybe, it will show up in more details in the server log (along with the 401 error).

[1] http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpsecuritymode%28v=vs.95%29.aspx

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