I have exposed a Sonic ESB process as a webservice and wrote a .NET application to upload data to it by calling its methods.
To this end, I have a library of complex object on the .NET side that I added in xml format to the web service definition on the Sonic ESB side. This is a necessary step in exposing the Sonic ESB process, because the methods to be called should be able to recognize the objects being passed from the .NET application.
However, when I try to add the service reference to the .NET application, the same library is treated as two different ones on each side of the service, because they are assigned to different namespaces. Making sure that ‘Reuse types in referenced assemblies’ is checked when creating the service reference makes no difference: The different types corresponding to one another are kept apart.
The following code thus yields an error:
public string PushManifest(FargoGate.DtoLib.OutboundFargoMessage message)
{
FargoGateOnRampWSRequest wsRequest = new FargoGateOnRampWSRequest();
OutboundFargoMessage outMessage = new OutboundFargoMessage();
//TODO ERROR: Cannot convert source type 'FargoGate.DtoLib.OutboundMessage' to target type 'PollFargoJob.FargoGateOnrampWS.OutboundFargoMessage'
wsRequest.OutboundFargoMessage = message;
throw new NotImplementedException();
}
Any suggestions would be greatly appreciated!
It would seem to me that I do not need svcutil.exe at all, as is suggested, but rather continue generating the schema for the data model using xsd.exe. I did just that to ensure that the data model was exactly the same on both sides of the service. However, for some reason, I could not create the webservice properly, as Sonic Workbench keeps on crashing whenever I try with the updated schema. Perhaps the schema is too complex for Workbench to handle?
Well, I now solved it by using a dirty trick. Instead of using WCF I am using a standard .NET 2.0 way of registering the webservice. In the Sonic ESB webservice, I set the input parameter type to string, rather than the data type from the library. In the .NET code calling the webservice operation, I serialize the object to xml and pass the resulting string to the webservice.
So instead of passing a serialized object, I am passing a string containing the xml of a serialized object. And that seems to work!
It’s a bad solution, I know, but I am desperate.