wcf client local function
I have the following class
[DataContract]
public class A
{
private List<B> b= new List<B>();
开发者_如何学Gopublic 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 ?
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:
精彩评论