I have a bizarre problem that is doing my head in.
I have the following classes defined in a single project:
public abstract class AbstractUnitModel { public void executeRemoteModel(){} } //this class also implements a seperate interface, but I dont think that is the issue public class BlastFurnaceUnitModel : AbstractUnitModel, IUnitModel {}
Now if I try something like this, it works as expected:
class Class1 { public void method1() { BlastFurnaceUnitModel b = new BlastFurnaceUnitModel(); method2(b); } public void method2(AbstractUnitModel a) {} }
Now I have another project that exposes a web method. This method takes an AbstractUnitModel and executes it remotely, then sends the results back to the client. So on the server I have this:
[WebMethod] public AbstractUnitModel remotelyExecuteUnitModel(UnitModelWrapperInterface.AbstractUnitModel unitModel) { unitModel.executeRemoteModel(); return unitModel; }
And on the client I have this:
public void remoteExecution() { var unitModelWebService = new UnitModelRemoteServer.RemoteModelExecutionWebService(); unitModelWebService.remotelyExecuteUnitModelCompleted += new UnitModelRemoteServer.remotelyExecuteUnitModelCompletedEventHandler(remoteExecutionCompleted); unitModelWebService.remotelyExecuteUnitModelAsync(this.remoteBF); }
But my project will not compile, and I get these errors: Error 109 The best overloaded method match for ‘CalibrationClient.UnitModelRemoteServer.RemoteModelExecutionWebService.remotelyExecuteUnitModelAsync(CalibrationClient.UnitModelRemoteServer.AbstractUnitModel)’ has some invalid arguments
Error 110 Argument ‘1’: cannot convert from ‘UnitModelWrapperInterface.BlastFurnaceUnitModel’ to ‘CalibrationClient.UnitModelRemoteServer.AbstractUnitModel’
I can not figure out why this is happening. I have references in the server project to the namespace where AbstractUnitModel is defined. The only thing that looked a little funny to me is that it is using AbstractUnitModel from the ‘CalibrationClient’ namespace rather than the UnitModelWrapperInterface. It seems when VS generates the proxy for a webservice on the client it creates a partial abstract implementation of AbstractUnitModel. Is this the source of my problem? If so, how might I go about fixing it?
edit for solution: As pointed out, the client needs to know about all classes that could be sent across the wire. I ended up solving this by removing the generated proxy classes and referencing the common library. Not ideal but good enough in this situation.
You might try
[XmlInclude]:Worth a try, at least…
(edit) Or at the method level:
(less sure about the second)