Click here to Skip to main content
15,918,706 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

1. I have a WCF service, deployed as part of an mvc3 application.

    public interface ILoadService
        string SayHello(string yourName);

// implemented as:
public class LoadService : ILoadService
               public string SayHello(string yourName)
            return "Server Said: Hello  " + yourName;

// The above service is deployed online with basicHttpBinding at some URL.

2. Im using code sharing techniques for Mono For Android, and hence my project setup for android app is as below

a. SharedLibrary : Which adds a Service Reference to the online WCF, and uses it to make calls through a proxy generated through SvcUtil.exe (automatically generated proxy). A file named abc.cs makes the WCF calls

using SharedLibrary.LoadServiceReference;
// WCF Service Added as Service Reference as above line.

using System;
using System.Runtime.Serialization;

public class LoadServiceLibrary

    public string SayHello(string yourName)
        using (LoadServiceClient client = new LoadServiceClient())
            var result = client.SayHello(yourName);

            return result;


b. SharedLibrary.MonoAndroid : An Android service library that adds abc.cs from SharedLibary "as a link" so that we resolve .net dll issues where SharedLibrary is a common library and SharedLibrary.MonoAndroid uses MonoForAndroid profile.

example: same file above --> as a link

c. I have a project, say AndroidApp, that first adds the SharedLibrary.MonoAndroid as an Existing Project to the solution, adds a reference to the added project. Now the idea is to use Native UI for Android (In future, iOS WP7).

Example Android App:
using SharedLibrary.MonoAndroid; // <<-- Problem
// The above reference will not resolve
// because: SharedLibrary.MonoAndroid in turn references, SharedLibrary
// which contains the WCF reference as using MyWcfService

[Activity(Label = "Second Page")]
public class SecondActivity : Activity
    private ProgressDialog progressDialog;
    protected override void OnCreate(Bundle bundle)


        progressDialog = new ProgressDialog(this) { Indeterminate = true };
        progressDialog.SetTitle("Getting Hello Signal");
        progressDialog.SetMessage("Please wait...");

        ThreadPool.QueueUserWorkItem(item => GetResponse());

    private void GetResponse()
        string serverResponse;

        using (LoadService client = new LoadService())
            serverResponse = client.SayHello("My Name");

            if (serverResponse != null)
                RunOnUiThread(() =>
      FindViewById<TextView>(Resource.Id.Response).Text = serverResponse;

Now the problem is... When i add abc.cs as Link to the SharedLibrary.MonoAndroid, the using statement contained in abc.cs (using MyWcfService) in the original project SharedLibrary does not resolve. If i add a new Web Reference, to SharedLibrary.MonoAndroid just to reslove the issue, the whole code sharing breaks down, where in in the future, i might have to add local Reference to SharedLib.iOS, sharedLib.Wp7..

Can anyone suggest a work around for this? because i don't want to break the chain of shared code, which is possible through the original shared library.

Any help is greatly appreciated. Thanks.
Updated 24-Oct-12 9:50am
joshrduncan2012 24-Oct-12 15:28pm    
Have you tried contacting Xamarin Support to see if they can help you with this issue?
robroysd 24-Oct-12 15:35pm    
Not yet, since, this is a code sharing issue and not anything perticular to Xamarin. I thought i'd give it a shot here. Maybe someone else has run into this issue before. The thing is, i'm using the technique from Greg Shackle's book and everything works. This is just tricky as there's a WCF reference. Will wait out for other answers. And i'm sure all the examples in Xamarin, depend on local code and not many use WCF. If they do, it's AJAX/REST etc.. not pure normal WCF.
Sergey Alexandrovich Kryukov 24-Oct-12 15:35pm    
I'm afraid to say, you don't have enough information. First, if you do the same in Windows .NET, will it work? Perhaps you need to create an absolutely minimal code sample, test it in different platforms (you can also do it, especially if this is console application sample), report exactly what's going wrong, and, if you still cannot figure out things, post it all here using "Improve question".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900