0

A Silverlight application (App1) currently uses a ASMX Web Service. The web service has a reference to an assembly containing classes. The silverlight application uses these "classes/objects" to communicate with the ASMX Web Service.

Another ASMX Web Service also contains a reference to the exact same assembly with the same classes. This ASMX Web Service is being used in another Silverlight application (App2).

Thus, these Web Services contain an assembly reference to the same assembly.

The Silverlight applications contain so called "Service References" for communicating with the web services. The first Silverlight application (App1) implements a User Control which is located in the second application (App2).

While the web services use the same classes, they are situated in different namespaces.

For example, App1.ServiceReference1.SomeClass and App2.ServiceReference2.SomeClass .

Is it possible to reuse the classes in both Silverlight projects without mapping them?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Ferhat
  • 1

1 Answers1

0

I haven't done this with Silverlight, but what happens if you add a reference to the shared assembly to your Silverlight projects, then make sure you have "reuse types" set in the service reference?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • Silverlight won't allow me to add a regular C# class library to the Silverlight project as an assembly reference. It only accepts Silverlight class libraries. However, a regular C# class library has been added as an assembly reference within the ASMX Web Services. – Ferhat Feb 13 '12 at 15:39
  • Can a Silverlight library be used by the ASMX service? – John Saunders Feb 13 '12 at 16:47
  • I've tried that and it produces the following warning: "The project 'TestLibrary' cannot be referenced. The referenced project is targeted to a different framework family (Silverlight)". I've also tried to supply the Silverlight Class Library class instance to the ASMX Web Service method (as a parameter) and it produces the following error. "Argument 1: cannot convert from 'TestLibrary.Class1' to 'App1.ServiceReference2.Class1'. – Ferhat Feb 13 '12 at 17:49
  • You may be out of luck. The fact that it's Silverlight changes things. Is there something like a portable library type? – John Saunders Feb 13 '12 at 18:30
  • -Edit: I've managed to get it working. I've added a reference to the Silverlight class library assembly (dll) instead of the project itself. That seems to be working. I've tried that after reading on sharing assemblies at http://blogs.msdn.com/b/dotnet/archive/2009/12/01/sharing-silverlight-assemblies-with-net-apps.aspx . I'm now able to use just one (Silverlight) class library and use the objects for communicating with the web service and even between the two applications! However, I've used a WCF Web Service (svc) instead of ASMX.I'm going to try it with ASMX and 2 web service projects. – Ferhat Feb 13 '12 at 18:39
  • -Update: This seems to be working with WCF services and not with ASMX services. For example, a WCF Service Reference allows me to execute client.DoWork2Async(TestLibrary.Class1 ...), the TestLibrary.Class1 type is also located at the client. However, ASMX Service References prefix the class as ServiceReference3.Class1 which produces client.DoWork2Async(ServiceReference3.Class1 ...). That isn't equal to the TestLibrary.Class1 type at the client. – Ferhat Feb 13 '12 at 18:57
  • You should be using WCF in any case. ASMX is a legacy technology and should not be used for new development. – John Saunders Feb 13 '12 at 19:14