tags:

views:

14

answers:

1

I have the following class

[DataContract]
public class A
{
    private List<B> b= new List<B>();

    public float getSum()
    {
        float sum= 0;

        foreach (B b1 in b)
        {
            sum+= b1.sum;
        }

        return sum;
    }

    [DataMember]
    public int B
    {
        get { return b; }
        set { b = value; }
    }

The function getSum() is domain specific function.
I have wcf service hosted in IIS and wcf client.

In the client I like to use the class A and to call the function getSum().
The function needs to be local call, not remote.

I like to use it this way:

A a = proxy.getA(101);

var1 = a.getSum();

A a1 = new A();
a1.setSomething
proxy.Insert(a1);

How can I do this with wcf ?

+2  A: 

The only way to achieve this is to use the same assembly containing this class on the client instead of generating a proxy. So put this class into a separate assembly that you will share between the client and the server. Obviously if your client is not .NET this won't be possible.


To reuse types from a given assembly you could use the /reference:<file path> switch when generating your proxy class instead of importing them from the WSDL of the web service and thus losing the getSum() (which by the way should start with a capital letter in order to follow good coding practices):

svcutil.exe /reference:AssemblyThatContainsTheClassA.dll http://example.com/test.svc?wsdl

or if you are using the Add Service Reference... dialog in Visual Studio:

alt text

Darin Dimitrov
I thought this could be a solution.
darko petreski
Yes it is a solution.
Darin Dimitrov
If I have an instance of a class from the assembly I cannot use it with the proxy.
darko petreski
Use it instead of the proxy
John Saunders
I need to use the proxy. Please see the question, it is appended.
darko petreski
@darko petreski, as @John and myself stated you cannot use the proxy anymore. You will need to share an assembly between the client and the server that contains this type. You could still generate a proxy but instruct [svcutil.exe](http://msdn.microsoft.com/en-us/library/aa347733.aspx) to pick types from a given assembly and do not import them from the WSDL using the `/reference:<file path>` switch.
Darin Dimitrov
Thanks. It helped.
darko petreski