We help IT Professionals succeed at work.

Best practice for extensive webservice API?

1,512 Views
Last Modified: 2013-11-18
I'm building a SOAP webservice API to allow our customers to integrate their external apps with our systems. This requires the webservice(s) to have a lot of operations, and many different .NET classes to serialize.

What I have done so far is split the API into multiple webservices (.asmx files using VS.NET).

- PersonHandler.asmx
- CompanyHandler.asmx
- ActivityHandler.asmx
- etc.

This way the names of the operations can be a bit shorter (e.g. CompanyHandler.Save(...) instead of SuperHandler.SaveCompany(...)) and the actual files becomes more manageable when developing the API, since I don't need a 100'000 line file with all the code.

To make the parameterlists and return values of the service easy to use I have made a set of classes which act as simple data holders with no methods.

- Company
- Person
- Activity
- etc.

The problem arises when I make a sample client (in my case also in .NET).

When I add a reference to the webservice (using VS.NET or wsdl.exe) the data holder classes are auto-generated for each service that references them (as part of the WS proxy/wrapper).
So if both the PersonHandler and CompanyHandler uses a Person object in a return or parameter value it causes problems. If the proxies are generated in the same namespace there is an obvious problem with an "ambigious reference" and if the are created in seperate namespaces it makes the client app unnecessarily complicated and means that you have two 100% identitical classes in two different namespaces (so you can't e.g. use the Person class returned from CompanyHandler.GetPersonsWorkingAtCompany(...) to call PersonHandler.SavePerson(...)).

See the included code section for an example which illustrates the problem.

Any suggestions?
//
// FICTITIOUS EXAMPLES OF SAMPLE CLIENT
//
 
//-- Example 1 - Ambigious reference problem --
 
//Will not compile. "Person" is an ambigious reference since it is generated both for the PersonHandler and the CompanyHandler webservice proxy
 
int companyId = 32;
CompanyHandler companyHandler = new CompanyHandler();
PersonHandler personHandler = new PersonHandler();
 
Person[] personsForCompany companyHandler.GetPersonsWorkingAtCompany(companyId);
Person somePerson = personsForCompany[0];
somePerson.Name = "James Brown";
somePerson.Email = "james@brown.org";
 
personHandler.SavePerson(somePerson);
 
//-- Example 2 - Using namespaces which cause "class mismatch" --
 
//Will not compile. We can not call SavePerson with the somePerson object since it is another "Person" class than the one returned by GetPersonsForCompany
 
int companyId = 32;
Company.CompanyHandler companyHandler = new Company.CompanyHandler();
Person.PersonHandler personHandler = new Person.PersonHandler();
 
Company.Person[] personsForCompany companyHandler.GetPersonsWorkingAtCompany(companyId);
Company.Person somePerson = personsForCompany[0];
somePerson.Name = "James Brown";
somePerson.Email = "james@brown.org";
 
personHandler.SavePerson(somePerson); //will not compile, somePerson is wrong class for SavePerson even though they are based on the same class in the code for the webservice that is called

Open in new window

Comment
Watch Question

Project Manager / Technical Lead
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
DarrenProject Manager / Technical Lead
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi Darren,
No, I had not found those links. I tried googling all sorts of word-combos, but they all drowned in "how to set up your first SOAP WS" articles.
"creating a seperate dll"
I also briefly considered that. But I would really rather not add additional plumbing and complexity to the client end.
"use an interface"
I'm fairly sure the ".NET to SOAP XML" serialization will strip that info away. I might give it a try though - just to make sure.
"change from Web Services to WCF"
That does in fact solve it (combined with setting specific namespace on the serialization attribute.
But I need the API to be easy for the client developers to use, even if they do not have much experience with WS-tech (also I would imagine that many WS-enabled programming environments are lacking such a feature).
I think I will try to change the services so the classes are only used in one service, since that would save me all kinds of trouble keeping things up to date, and explaning the issue to client programmers.
Thanks for your help. At least now I know that I'm not missing some obvious solution and what my work-around options are.
Best regards,
Torben
DarrenProject Manager / Technical Lead
CERTIFIED EXPERT

Commented:
Hi Torben,

Glad I could be on some help.

I agree with you, the final solution you stated is the one I use most frequently.

Even in WCF I just try to keep as many classes in one place but it is a pain if you have lots of operations.

Cheers,

Darren

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.