When working in a Service Oriented Architecture there are two main problems I get asked a lot about.
Problem
To put some context around these two main questions. Traditionally services are discovered by either searching the source tree or by word of month. Neither of which is a great solution. Services are either lost in thousands of lines of code, or lost in communication.
As for sharing object types across services. By design services are usually developed with in its own domain and shouldn’t share types. But!, in some cases, you might actually have a business need to share certain types. For instance, if you had two services within the same assembly that referenced a single object, when you created two different service references to the services, two objects will be defined under two different namespaces.
Solution
Disco files were created to answer these two very obvious questions. With a disco file, developers can maintain a global list of available services. Every time a new service is created, add the new WSDL URL to the list of services. This list is the single point of reference when creating a Web or Service Reference. Also, since there is only one global reference to all the services, the generated code will generate one namespace and recognized that if there are any shared types across services, it will only generate the type once.
Create the disco file number the vroot of your application. Below is an example disco file.
1 2 3 4 5 | <?xml version="1.0" encoding="utf-8" ?> <discovery xmlns="http://schemas.xmlsoap.org/disco/"> <contractRef ref="http://localhost/ServiceA.svc?wsdl" docRef="ServiceA.svc" xmlns="http://schemas.xmlsoap.org/disco/scl/" /> <contractRef ref="http://localhost/ServiceB.svc?wsdl" docRef="ServiceB.svc" xmlns="http://schemas.xmlsoap.org/disco/scl/" /> </discovery> |
Consuming the disco file is no different: