开发者

Unable to set CookieContainer on service client in MonoTouch

开发者 https://www.devze.com 2023-02-19 08:10 出处:网络
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.

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开发者_如何学JAVA 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号