View Full Version : web service namespaces
spmva
06-12-2005, 12:34 PM
I'm sure the answer to my problem lies somewhere on the Internet, but I'm having trouble articulating my issue to google for an answer.
On the server, let's say I have two web services that share a common set of classes.
For example:
public class WebService1
{
public CustomUser FindUserById(long id)
{
}
}
public class WebService2
{
public Things FindByUser(CustomUser user)
{
}
}
The obvious class in common here is "CustomUser".
When I point wsdl.exe at each of these web services, wsdl.exe wants to place the generated proxies in two separate namespaces, effectively duplicating the CustomUser in each one. How can I make both of these web services use the same CustomUser?
Thanks,
Steve
Mark Pollack
06-12-2005, 11:07 PM
Hi Steve,
Basically you have to specify the namespace explicitly and do some editing on the generated proxy class. Putting the custom types in their own assembly would be a best practice. The following MSDN article (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service07162002.asp) should prove to be useful in the details. Also this news group post (http://groups-beta.google.com/group/microsoft.public.dotnet.framework.aspnet.webservic es/browse_thread/thread/ab4685053a2e0afe/70a307b7005f309d?q=wsdl.exe+sharing+types&rnum=2&hl=en) provides some additional links and background info. The limitations of wsdl in this respect obviously don't make for a great developer experience if you are updating the web service frequently.
I haven't yet tried the Contract First Web Services (http://www.thinktecture.com/resources/software/wscontractfirst/default.html) software but it looks like it does the right thing with custom types. However, it starts with the XSD and not C# classes which may or may not be important to you.
Let us know how it goes.
Cheers,
Mark
spmva
06-13-2005, 11:47 AM
I guess that sometimes the most obvious answer is the only answer. I felt that there had to be some other explanation beyond proxy editing by hand. Thanks for pointing out those resources.
spmva
06-18-2005, 11:54 AM
.NET Framework 2.0 (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/wsnetfx2.asp) has the answer to type sharing across multiple web services:
Type Sharing
In many real-world scenarios, you may want to factor your application's functionality into individual services that group methods that logically fit together. This typically leads to sharing one or more data types between those Web services. For example, you may have an Order Entry service that returns an Order object and an Order Status service that takes in an Order object. Today, a client that wants to consume both of these services ends up with two different Order classes, making it cumbersome to take the output of the first service and pass it to the second.
Version 2.0 of the .NET Framework introduces a feature that provides the client with one Order class that's shared by the two service proxies. This feature is exposed on wsdl.exe with the /sharetypes switch. When using this switch you supply the URLs of two or more WSDL documents on the command line. For example:
wsdl.exe /sharetypes http://localhost/webservice1.asmx?wsdl http://localhost/webservice2.asmx?wsdl http://localhost/webservice3.asmx?wsdl
The code generation engine recognizes when types are equivalent based on their names and namespaces, and by comparing their Schema definition.
I guess that's not helping me today.
spmva
06-30-2005, 03:59 PM
I just wanted to tie up this topic. After hacking at the wsdl tool (mentioned in my other post (http://forum.springframework.net/viewtopic.php?t=122)) for several hours, trying to make it generate shared custom types, I decided that it was taking too long to accomplish. If I didn't have more immediate project deadlines to deal with, perhaps my efforts could have continued.
In any case, my final solution was pretty simple. I wrote a program that just parses the webservice proxy class files for the custom types and writes them to separate files, removing the duplication. For simplicity, I just placed all the custom types in the same namespace as the webservices so that they could be shared across them.
I then just wrapped all that up in an few NAnt tasks and moved on. Sorry...I wish I had something better.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.