Using WCF

From $1
    Table of contents

    MonoTouch contains experimental support for WCF services.  This small how-to explains what needs to be done to consume a WCF service in MonoTouch.

    Step 1: Generate the WCF proxy

    As of the time of writing this document, Mono 2.4 does not have a svcutil that is compatible with MonoTouch, so you need to use the slsvcutil that Microsoft provides as part of the Silverlight 3.0 Tools to generate the client proxy.  To do this:

    1. Launch a command prompt
    2. Run C:\Program Files\Microsoft SDKs\Silverlight\v3.0\Tools\SlSvcUtil.exe /noConfig http://yourdomain/yourservice/wsdl

    SlSvcUtil will generated a service.cs, you should copy this file to your Mac to use it with MonoTouch.

    Step 2: Setting up your project

    Select your project from the solution pad, and click Project->Edit References, you should get a window that looks like this:

     Picture 4.png

    Ensure that you have selected System.Runtime.Serialization, System.ServiceModel and System.ServiceModel.Web.  After you have added the references, add the service.cs file from Step 1 to your project.

    If you are running MonoTouch 1.1.0, service.cs will contain a reference to System.ServiceModel.Channels.IHttpCookieContainerManager in the CookieContainer property, this is not supported currently in MonoTouch, so you should either comment our remove the entire CookieContainer property.  This is fixed in >= 1.1.1

    Step 3: Invoke your service

    Sample service invocation:

    // Ensure you use the Binding,EndpointAddress constructor as MonoTouch does not support System.Configuration
    foo = new FooClient (new BasicHttpBinding (), new EndpointAddress (""));
    // Subscribe to the completed event for the invocation you want to make
    foo.AddCompleted += delegate(object sender, AddCompletedEventArgs e) {
                    Console.WriteLine (e.Result);  
    // Invoke the service
    foo.AddAsync (1, 10);



    Tag page
    • No tags

    Files (1)

    FileSizeDateAttached by 
     Picture 4.png
    No description
    115.78 kB02:14, 7 Oct 2009KangarooActions
    Page last modified 04:29, 9 Oct 2009 by Kangaroo