Web services og polymorfi
Hej Eksperter,Jeg får nedenstående fejl når jeg kalde min web service, hvor jeg sender et objekt som nedarver fra en abstrakt klasse. Er der nogen der kan hjælpe mig?
InvalidOperationException.
The type WebLookupService.Service.CommandQueueService was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically
Testkode:
IService service = new CommandQueueService(".\\TestQueue");
RegistrationServiceProxy.Instance.Register(service); //<-- Fejler
namespace WebLookupService
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class WebLookupService : WebService
{
private readonly RegistrationService registrationService;
private readonly Service.LookupService lookupService;
public WebLookupService()
{
Services services = new Services();
registrationService = new RegistrationService(services);
lookupService = new Service.LookupService(services);
}
[WebMethod]
public void Register(IService service)
{
registrationService.Register(service);
}
}
}
namespace WebLookupService.Service
{
[Serializable]
public abstract class IService
{
public abstract void Stop();
public abstract int GetLoad();
public abstract ServiceTypes GetServiceType();
}
}
namespace WebLookupService.Service
{
[Serializable]
public abstract class ICommandQueueSendService : IService
{
public abstract void sendCommand(ICommand command);
}
}
namespace WebLookupService.Service
{
public class RegistrationServiceProxy : IRegistration
{
private static readonly ServiceProxy.WebLookupService serviceProxy;
private static readonly RegistrationServiceProxy instance;
public static RegistrationServiceProxy Instance
{
get { return instance; }
}
static RegistrationServiceProxy()
{
instance = new RegistrationServiceProxy();
serviceProxy = new ServiceProxy.WebLookupService();
serviceProxy.Url = "http://localhost/Service1.asmx";
}
private RegistrationServiceProxy()
{
}
public string WebServiceURL
{
get { return serviceProxy.Url; }
set
{
serviceProxy.Url = value;
}
}
public void Register(IService service)
{
serviceProxy.Register(service);
}
}
}