无法在 MonoTouch 中的服务客户端上设置 CookieContainer

发布于 2024-10-26 12:29:55 字数 1094 浏览 7 评论 0原文

我有一个 MonoTouch 项目,使用与 Windows Phone 7 应用程序共享的一些代码。此共享代码为使用 SLSvcUtil.exe 生成的 RIA 域服务(使用 /Soap 端点)创建 WCF 代理。代码如下所示:

BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://someurl/someservice.svc");

var client = new MyDomainServiceSoapClient(binding, address);
client.CookieContainer = _cookieContainer; // <-- EXCEPTION here

这段代码在 WP7 中有效,但在 MonoTouch 中失败,我找不到原因。我在 MonoTouch 中遇到的例外是:

System.InvalidOperationException: Unable to set the CookieContainer.
Please make sure the binding contains an HttpCookieContainerBindingElement.
    at MyDomainServiceSoapClient.set_CookieContainer

在设置 CookieContainer 之前我已尝试了以下选项,但仍然出现相同的错误:

binding.EnableHttpCookieContainer = true;
binding.AllowCookies = true;
binding.CreateBindingElements()
    .Add(new HttpCookieContainerBindingElement()); // ??

更新:我还尝试手动构建 CustomBinding 并添加 HttpCookieContainerBindingElement 但这也不起作用。

有什么想法吗? MonoTouch 网站告诉我 WCF 实现是“实验性的”,所以这也许是当前版本的 MonoTouch 的限制?

I have a MonoTouch project using some code I share with a Windows Phone 7 app. This shared code creates a WCF proxy for a RIA Domain Service (using the /Soap endpoint), generated using SLSvcUtil.exe. This is what the code looks like:

BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://someurl/someservice.svc");

var client = new MyDomainServiceSoapClient(binding, address);
client.CookieContainer = _cookieContainer; // <-- EXCEPTION here

This piece of code works in WP7, but fails in MonoTouch, and I can't find why. The exception I get in MonoTouch is:

System.InvalidOperationException: Unable to set the CookieContainer.
Please make sure the binding contains an HttpCookieContainerBindingElement.
    at MyDomainServiceSoapClient.set_CookieContainer

I have tried the following options before setting the CookieContainer, but still the same error:

binding.EnableHttpCookieContainer = true;
binding.AllowCookies = true;
binding.CreateBindingElements()
    .Add(new HttpCookieContainerBindingElement()); // ??

Update: I have also tried building a CustomBinding by hand and adding an HttpCookieContainerBindingElement but this also won't work.

Any ideas? The MonoTouch site tells me that the WCF implementation is "experimental", so maybe this is a limitation in the current version of MonoTouch?

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

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

发布评论

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

评论(2

谈情不如逗狗 2024-11-02 12:29:55

我不知道 SLSvcUtil.exe 作为 Monotouch 的代理生成器效果如何,但我总是将它与 Silverlight 结合使用,因为 Silverlight 是 WP7 原生的,这就是它在那里工作的原因。

在 MT 中,您可能需要以 MT 方式进行操作,打开 MonoDevelop 并从那里添加对服务的引用,以便使用 Mono 框架及其 WCF 代理实现创建它,而不是为 Silverlight 服务代理生成代码。

至少,这对我有用,并且适用于使用基本 HTTP 绑定的 WCF 服务。

I do not know how it is with SLSvcUtil.exe as the proxy generator with Monotouch, but I always used it in combination with Silverlight, as Silverlight is WP7 native, it is why it works there.

In MT you probably need to do it MT way, open the MonoDevelop and add the reference to the service from there so it is created using the Mono framework and its WCF proxy implementation rather than generated code for Silverlight service proxy.

At least, this works for me and works well to WCF services using basic HTTP binding.

情场扛把子 2024-11-02 12:29:55

事实证明,这是 Mono 框架中的一个错误。从 MonoTouch 4.0.1 开始,这个问题已经解决,所以我可以毫无问题地使用上面的代码。

It turns out that this was a bug in the Mono framework. As of MonoTouch 4.0.1, this is resolved, so I can use the above code without problems.

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