I have a project with two dll’s (I’ll name them A & B).
In the first dll I want to pass a object of a web reference to my other dll.
The two dll’s use properties from the object so I have added a web reference to the service in both my dll’s.
But when I want to pass this object I get an error:
The best overloaded method match for 'method in dll B (B.com.test.services.Task)' has some invalid arguments.
So my dll A expects it to be a object of type A.com.test.services.Task while it gets an object of type B.com.test.services.Task.
How do I fix this?
Some code:
Dll A:
using A.com.test.services
public string BuildDetail(Task task, bool TaskExecutionState, bool TaskComment)
{
DetailScreen detail = new DetailScreen(task); //error is here.
return detail.Layout;
}
Dll B:
using B.com.test.services
public DetailScreen(Task task)
{
//some code
}
The problem is that creating a web reference means that proxy classes are created for each types of the referenced service.
Suppose you have your dll, A.dll and you create a web reference to a service with the type
Task. Inside A, a proxy type, let’s call itA.Taskwill be created. The typeTaskandA.Taskare two different types,Taskexists on the server,A.Taskexists on the clientThen, you have another DLL, B.dll and once again you add a web reference. This time, yet another proxy type will be created, let’s call it
B.Task. And althoughA.TaskandB.Taskprobably look alike, they are two different types (most probably they exist in two different namespaces).There are two possible approaches. First – create your own mapping classes with methods which take
A.Taskand makeB.Taskout of it (and the other way around possibly).But the other approach involves creating a “common language” – a shared DLL (let’s call it
Task.dll) where you put yourTaskclass. You reference the DLL everywhere, in your webservice, inA.dlland inB.dll. Everytime you create a web reference, you make sure that the option “Reuse types from referenced assemblies” is checked (at reference properties page).This way, there will be no proxy types created for the type
Task– the same class will be used at the server side and at the client side. There will be then no need to convert anything and you will be able to pass references around.