1

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?

Roy
  • 494
  • 4
  • 17
  • It seems this issue has reappeared in MonoTouch 4.0.4.1. Everything was working fine in 4.0.3. Did you ever find a way of working around it? –  Aug 01 '11 at 08:40
  • I can confirm the issue still exists in MT 4.0.7 – Dale Sep 21 '11 at 02:19

2 Answers2

0

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.

Pavel Sich
  • 1,299
  • 10
  • 10
  • The idea here is that the code is shared between the MT app and the WP7 app. I think a piece of code to construct the correct binding for this situation would be a better idea. – Willem Meints Mar 25 '11 at 06:12
0

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.

Roy
  • 494
  • 4
  • 17