views:

259

answers:

3

Hi All,

I have a typical setup. The solution contains a regular .NET class library for business objects, A WCF project, a silverlight project and supporting web-app project, and some silverlight class libraries. The classes in my business class library are all marked with the "[serializable]" attribute. The WCF service has a method that would return a List of one of the objects in my business class library. When I add reference of this service in my silverlight class library project, the proxy is generated without any errors, but this proxy does not contain any definition of the service or the service interface itself. It does contain the definition of the complete object model contained inside the business object I am returning from the service, but without the actual reference to the service client I am unable to make a call to the service. Is there an issue with the design or implementation of this setup?

+1  A: 

Have you added the attributes [OperationContract] and [ServiceContract] to your WCF interface?

Henrik Söderlund
Yes I have. Please note it is only when I expose this method returning a business object that resides in a referenced assembly, that I see this issue. The moment I comment that operation from service interface and service implementation, the proxy is generated just fine.
DG
A: 

Make sure that your business object is marked as a [DataContract]. Any objects that it contains also need to be marked with that attribute as well.

EDIT: Since you don't want to make modifications to the 3rd party code, perhaps it's possible to create a manual proxy for your service, including the types defined there.

Here's an article all about using WCF the Manual Way.

Terry Donaghe
As I mentioned earlier. The business objects live in a separate DLL. This is legacy code which is why I am apprehensive about making changes to it. But the business objects all contain the [serializable] attribute in their definitions. Is there another way, I can transfer these business objects from the service end to the client end, without making changes to the referenced library code?
DG
A: 

Have you tried using the slsvcutil.exe tool from the command-line to generate the proxy instead of using "Add Service Reference"? That may at least spit out some warnings while generating the proxy to help you track down your problem, and gives you greater control over various options for the proxy.

Dan Auclair
Thanks for pointing me in the right direction Dan. The size of generated proxy using slsvcutil is 450KBs while using the "Add Service Reference" method it was just about 50KB. The proxy generated by slsvcutil is complete in every sense. However, it is now throwing a compile time error. Some of the business objects contain delegates. Instead of having these properties as delegates, the generated code has them as partial classes deriving from System.MulticastDelegate. As we cannot derive from System.Delegate or System.MulticastDelegate, there are compilation errors. Please suggest
DG
Glad that got you started. Are the delegates specifically a parameter or the return type of a method on the service contract? I think you are getting the error because delegates aren't able to be serialized by WCF. If they are not essential you could just leave them out of the contract by not marking them with [DataMember]. See this SO post http://stackoverflow.com/questions/957474/system-componentmodel-propertychangedeventhandler-cannot-derive-from-special-cl
Dan Auclair