Sunday, February 13, 2011

Best way to reverse-engineer a web service interface from a WSDL file?

I've inherited a WSDL file for a web service on a system that I don't have access to for development and testing.

I need to generate a web service that adheres to that WSDL. The wrapper is .NET, but if there's an easy way to do this with another platform, we might be able to look at that. The production web service is Java-based.

What's the best way to go about doing this?

Note: The inherited wsdl doesn't appear to be compatible with wsdl.exe because it doesn't conform to WS-I Basic Profile v1.1. In particular, the group that passed it on mentioned it uses another standard that the Microsoft tool doesn't support, but they didn't clarify. The error is related to a required 'name' field:

Error: Element Reference '{namespace}/:viewDocumentResponse' declared in
schema type '' from namespace ''
       - the required attribute 'name' is missing

For clarity's sake, I understand that I can easily create a .NET wrapper class from the WSDL file, but that's not what I need. It's like this:

Update: The original web service was created using Axis.

Diagram of system showing unavailable web service and mock web service

  • You may find useful the command line utility wsdl.exe of .NET by using the /serverInterface option. According to the documentation:

    Generates interfaces for server-side implementation of an ASP.NET Web Service. An interface is generated for each binding in the WSDL document(s). The WSDL alone implements the WSDL contract (classes that implement the interface should not include either of the following on the class methods: Web Service attributes or Serialization attributes that change the WSDL contract). Short form is '/si'.

    paulwhit : this helps. although the inherited wsdl doesn't appear to be compatible with it because it doesn't conform to WS-I Basic Profile v1.1.
    Panos : If you are getting just warnings and the code is generated, probably you can use it without problem. Wsdl.exe always tries to generate Basic Profile compliant code unless there is something in WSDL that is not compatible.
    Panos : Moreover, if you build the ws client proxy from visual studio you probably received similar warnings. You can create a client proxy with wsdl.exe and compare it with the one that you have in your project.
    paulwhit : it's a stop error; no code's generated :( I'll add more info to the question.
    From Panos
  • Try mock the wrapper interface using RhinoMocks and StructureMap .

    paulwhit : Does this handle the generation of web services? I can't seem to find that information readily available, and it doesn't look applicable on the surface. I meant "mock" in the generic sense, but maybe it's still applicable?
    From IceHeat
  • Not sure if this will help,

    what i've done recently is:

    • Generate .cs file using the wsdl tool or visual studio
    • I've changed it to be a partial class
    • I've created another partial class, in which all it does is add a line to say that the class implements IWhatEver
    • I've created an interface that is the same as the generated proxy class (Therefore the the proxy fully implements the interface)

    Then i've used a Mocking framework (Moq) in my case, to mock the WebService, I've then used poor mans dependancy injection (pass the mock into a constructor of the class under test) .. which can handle an instance of IWhatever

    Test away..

    Hope that helps

    paulwhit : I tried wsdl.exe and it's not compatible with the inherited wsdl because it doesn't follow the standard. :( After that, I'm not sure I need a mocking framework; couldn't I just change the proxy class URL setting?
    From danswain
  • We are using WSCF - Web Services Contract First tool from Thinktecture to do web service development creating XSD schema first and then generating service interfaces using this tool. It may be useful to generate service interfaces from WSDL but I have not tried this yet myself.

    paulwhit : That's pretty slick. Didn't work, but I can use this for other things! :)
    paulwhit : (Should clarify that it *does* work for my purpose, but I'm still dealing with a borked up WSDL that I think can only work on the original app that generated it (Axis). Trying that next)
    paulwhit : Accepting because I think this would be the best way except in my edge case with a messed up WSDL.
    Vlad N : I'm glad that it helped you somewhat. ;-)
    From Vlad N
  • Yes - you can use WSCF (as per above) to generate server side code. The actual URL can then be overwritten to point to the test URL that you want to use.

    However, this just generates a stub. You still have to code the actual e.g. GetCustomers() method which is somewhat suspect because you have no idea how the actual implementation works.

    Then you can either mock this or create a simple ASP web server to run it.

    From nzpcmad

0 comments:

Post a Comment