views:

35

answers:

2

I have a Silverlight Class Library that I want to use in both my Silverlight and my WebService project.

I am able to create and reference the Library in both projects without any problems, but when I try to use any of the classes in the Library on the Silerlight project, I get an ambiguous reference error between my Library and the Asmx Webservice (apparently, the silverlight project believes that the classes in the class library exist in the webservice).

How can I correct this issue? I have tried rebuilding and cleaning, but it does not seem to work. Can anyone help?

A: 

Sounds like the objects you are passing to Silverlight, via the WCF service, are the same objects in your class library. In that case the generated web-reference objects will be given the same names. Linking with the library will then give you 2 sets of objects with the same names.

If you install RIA services, once feature is the ability to share code between client and server by simply adding ".shared" in the class filenames before the extensions. ASMX services are so last century :)

if you don't want to learn the RIA services way of sharing objects across the great-web-divide (which I would recommend), you need to separate the data objects from the functionality you actually want to share client and server side.

To give more specific advice on your current set-up I would need to see more about how it is structured.

Enough already
I basically started this project without the knowledge of webservices and ASMX happened to be the one I picked, but it has now grown rather large so I have not bothered to change it. As far as its structered, I have all my "Data Classes" in the Library, and I have an Using "ClassLibrary", with a reference to the Class library DLL, in my web service class (I have all my web calls in this class). Furthermore, I have the Class Library reference in my Silverlight project as well as a USING "ClassLibrary" and "WebService". When I try to use a data class in the silverlight, I get the ambigous error.
gfeli
Basically that is the type of situation RIA services was designed to solve. While it may seem daunting moving dozens (or even 100s) of classes to RIA services will not be as painful as it sounds and will make your life easier going forward. I now have RIA service libraries which came in pair projects. You link one to your SL app and one to the website. Works a treat. Do some quick research on RIA and then make your decision. I can't think of an easy answer to your current situation using a single traditional library. Cheers
Enough already
A: 

A technique you can use is aliasing your using statements:

using MyNameSpace = My.Name.Space;
using MyWebService = My.Web.Service;

Then access all of your objects with these aliases to remove the ambiguities.

Joel Etherton
This works but I get type conversion issues which is what I wanted to avoid.
gfeli
@gfeli - Have you specified namespaces all the way to the root level so that the web service does not take over the object's namespace? If your webservice returns the full namespaced object like My.Full.NameSpace.Type then there shouldn't be a type conversion problem.
Joel Etherton