views:

137

answers:

3

Hi,

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!

A: 

Hello, i confronted the similar problem recently, there are few links that helped me out, the main point is try to use tools like SVCUTIL, not with VS:

http://kjellsj.blogspot.com/2008/06/wcf-using-shared-types.html

http://msdn.microsoft.com/en-us/library/aa702581.aspx

Andrew
Same as above... Thanks for the tip! I will investigate and report back.
Fedor Steeman
I am not used to using svcutil, and find the documentation confusing at first glance. Any tips on what switches to use in order to generate the schema for the library?
Fedor Steeman
http://www.codeproject.com/KB/WCF/WcfTypeSharing.aspxHere is example, sorry, just couldn't find link in history yesterday :). But actually i confronted a little different problem, i wanted to share types between services (Work with 2 services that operate same DataContract), not between service and classes, and sharing types between services and classes actually break one of the SO principle http://msdn.microsoft.com/ru-ru/magazine/cc164026(en-us).aspx.
Andrew
I am not sure we understand each other: I need to have a xml schema definition file (xsd) generated from the library that I can put into the esb process for sharing the types. Normally, I simply use xsd.exe for that, but are you saying that I need to svcutil.exe now I did I misunderstand?
Fedor Steeman
It seems i misunderstood. Though through svcutil (like when you do "Add Service Reference") you generate some proxy classes based on xsd, wsdl etc, you can see them in Reference.cs. Server and client share DataContracts, not classes. Svcutils can help you with generating proxy classes that won't create proxy class for shared types, actually you can just wrote convert function PollFargoJob.FargoGateOnrampWS.OutboundFargoMessage to FargoGate.DtoLib.OutboundFargoMessage and vice versa if needed.
Andrew
A: 

Try Identical Types In Separate Web Services, and specifically the first answer there.

I don't have a clear picture of what you're doing but it seems like that's what you need.

Cheeso
Thanks! It had not occurred to me that the class library may have changed in the meantime. I will try to update the schema using svcutil and try again. Any tips on making sure the namespaces are identical too?
Fedor Steeman
A: 

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.

Fedor Steeman