Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monotouch and WCF: difference of SVCUTIL.EXE and SLSVCUTIL.EXE and how to avoid unsupported generic ChannelFactory?

I'm (again and still) trying to consume some WCF services in Monotouch. First approach: add a web reference in Monodevelop failed. It cannot create the reference file. Then I tried SVCUTIL.EXE and get an error that the generic ChannelFactory is not available in Monotouch - I suppose because there is no reflection available.

Next I tried SLSVCUTIL.EXE from the Silverlight 3 SDK. This generates namespaces for the various services that differ from those created through SVCUTIL.EXE. As I have already lots of wrapper code I have to change a lot.

These questions arise:

  • Can I override the CreateChannel methods and return specialized channels for each service instead of being dependent on the non-existing generic version, as proposed by the exception that gets thrown? This means fixing the code generated by SVCUTIL.EXE.
  • How do I create a channel in an overridden method? I only have interfaces of my services. I googled and could not find any examples. What does code look like that has to be written in that method?
  • Totally unclear to me: what is the difference between the two service utilities?
  • If I get the namespace issue sorted out, will the stubs created through the Silverlight utility make my project work, or will that also suffer from the generic channel issue?
  • why can the Silverlight tool work without dynamically emitting code? What is the difference in the outputted code and what advantage does the dynamic version have?
  • which version of Silverlight is supported int MT. Can I use the tool of v4 or does it have to be version 3?
  • Does WCF in MT support streaming, like downloading large files?
like image 536
Krumelur Avatar asked Nov 25 '11 22:11

Krumelur


1 Answers

WCF is a huge beast and it's very difficult to give general answers on it, too much depends on details. The general rule is that MonoTouch supports the same subset of WCF that was shipped with Silverlight (even if a few additions were made over time).

I suppose because there is no reflection available.

Reflection is available and works with MonoTouch. Reflection.Emit does not since Apple does not allow JIT'ing code on iOS devices. This can limit some API that requires code generation at runtime (but is not an issue if the code generation can be done at compile time).

... This means fixing the code generated by SVCUTIL.EXE. ...

Fighting/editing generated code is usually a bad idea (e.g. future maintenance). I suggest you try to use slsvcutil.exe before investing too much time in customizing the generated code.

... What does code look like that has to be written in that method?

The full source code for Mono's System.ServiceModel and System.ServiceModel.Web are available if you wish to provide your own channel (or customize the generated code).

Totally unclear to me: what is the difference between the two service utilities?

The SL prefix, in slsvcutil.exe, is for Silverlight. Microsoft made this tool to generate code that will only use the WCF subset available in Silverlight. Since this is the same subset supported by MonoTouch this is the best tool to use.

If I get the namespace issue sorted out, will the stubs created through the Silverlight utility make my project work, or will that also suffer from the generic channel issue?

It should work. That's how people are using (the available subset of) WCF with MonoTouch today. If there are issues with this (subset/tool) you can fill a bug report about it (with a test case) and we'll have a look at it.

like image 157
poupou Avatar answered Nov 13 '22 22:11

poupou