Referencing a class in a web service  
Author Message
swellbow





PostPosted: ASMX Web Services and XML Serialization, Referencing a class in a web service Top

Hi,

Consider the following project structure. I have a single solution with two projects. One project is a web service class. The second is a windows application. The windows application has a reference to the web service. The web service has a single web method which i will call in the windows application. Additionally, my web service has a public enum (or class) which I would like to be able to reference in the windows application. However, unless I use the enum (or class) as a parameter of or return type of the web method, I cannot access the enum (or class) in the windows application.

Is there some way to make any public class or public enum in a web service project available to consumers The workaround I have found is to simply add a parameter into my webmethod which acts as a dummy reference, so that the web reference in the windows project generates a local class to reference it.

It seems to me that making a class public in an assembly should make that class public to anything that references it. This works fine in a windows environment (like a windows project referencing a DLL) but not in a web environment.

Thanks for any help!

Kurt



.NET Development27  
 
 
rfreire





PostPosted: ASMX Web Services and XML Serialization, Referencing a class in a web service Top

Kurt,

Web services projects behaves differently from Class Library projects as they are intended to be a SOA implementation... this means many things.... and one of them is that communication is based on data contracs (wsdl)... this is not the case of class libraries.

So as you mention.... a way to implement what you want is to add this enum in the data contract adding this in a webmethod signature.

However.... the way I would suggest is to put your enum along with any other common or entity classes in a common class library, referenced from both, Windows App and Web Service project. So, in that case.... you will have this class available in both places without needing to add a dummy method in the WS.

Rgds

Rodrigo


 
 
DmitryMS





PostPosted: ASMX Web Services and XML Serialization, Referencing a class in a web service Top

I suppose creating dummy references, despite of its unelegance is the only way to go... Keeping that class on a client doesn't actually solve the problem.