Parsing a WSDL to extract Service / Port elements - java

I want to automatically process a WSDL file to discover defined Service / Port elements. Is this possible, using Java or some sort of Ant utility? If so, how?

JAX-WS does indeed contain WSDL parsing code and does allow you to inspect the WSDL ports and services.
If you are looking for something that might be more robust, allows you to manipulate or inspect other parts of the WSDL, WSDL4J might be useful for you. WSDL4J may also have the added benefit of not being an endorsed "Standalone Technology" meaning that you can easily include it in your classpath without worrying about it conflicting with the version of the JVM your code runs on.
If you actually have to make Web service calls and only need to inspect the high-level parts of the WSDL, JAX-WS will work fine. If you need something more portable without possible configuration overhead and/or you don't actually need to make Web service calls, WSDL4J may be a better choice.

The .NET framework has the System.Web.Services.Description.ServiceDescription type that will help, but you might want to check out this...
http://mikehadlow.blogspot.com/2006/06/simple-wsdl-object.html
... which shows you a "simple WSDL object".

Related

WSDLS generated in the background by servlet containers?

Recently I read the article http://www.ibm.com/developerworks/library/ws-noide1/ and this prompted me to review my knowledge of just how the SOA had evolved in the last decade or so. The review was a nice refresher however I soon discovered some gaps in my knowledge.
In particular I want to know, and could not find a definitive answer for wheather WSDL files are necessary regardless of which protocol, paradigm, or API is used in providing the web service. Is the creation and propagation of these files done by the servlet containers such as tomcat , jetty etc in the background?
Essentially HTTP protocol itself for example does not require a WSDL which leads me to believe that WSDL is a specification closely coupled to SOAP and that perhaps EJB, Spring, etc do not use require it.
I know similar questions to this have been asked such as JSON, REST, SOAP, WSDL, and SOA: How do they all link together
but I haven't been able to find a definitive answer to this specific question.
If you take a closer look to the Java specification you'll have a clue of what is clearly the WSDL.
When you build a Web Service in Java you have several way to do it.
SOAP, spec Jax-WS : this standard is kind of strict. It order to communicate with it you have to respect a contract. This contract, named the WSDL, is an XML that define how to reach the WS, which parameters are needed and what are their types. This file is provided by the service and most of modern IDE would generate it but you have to provide it to your client so it can call the WS respecting the contract.
REST, spec Jax-RS : this standard is far less strict as you have no contract. This provide an URL over a specific HTTP method (GET, POST, PUT, DELETE). To make a call to this kind of WS, just call it and you'll see what happen.
Queue JMS : this is a kind of different as the two others but seems important to me as it provide a way to create messaging reliable, decoupled et asynchronous. It is based on a connection factory to deals with the communication.
These standard are implemented in most of the main technologies today. Java EE with its EJB has implementation for the three of them, as do Spring.
SOA provides many ways to communicate now, depending on what are your needs.
I hope I helped, don't hesitate to ask if needed.
EDIT:
To explain use case I'll try to set up an example... It's a kind of hard exercise and not perfect but I hope it will help you.
Consider, you work for a house seller. You have three different call to WS: 1. you confirm a sale on your website, 2. you search in your catalog, 3 you inform your boss via a small message on the intranet.
I precise that using three different type of WS is not compulsory.
This action is really important for your workflow. Data that are
sent must arrived. You must be sure to respect what is expected on
the WS. Client side and server side must be perfectly matching.
You'll use SOAP because there is a specific contract between these
two sides.
For this you don't need a specific and rigid contract. Searching is just easy and does not need a structure with defined arguments. Just get data and print it on the screen. Here REST is maybe more suitable because it is easier to set up and if modification are needed, there is no contract to modify on client side.
For messaging, you want to send the message and that's all. JMS are queues waiting for "message". These messages are requests that will be consume asynchronously. The message will be stored waiting for a consumer to take them in the queue order (FIFO).
The generation of the WSDL is your task. It will generate an xml file based on your Java code of the WS. Notice that the contrary is possible too, if you have a WSDL you can generate the Java from it(see this. Most of the time you have an url corresponding to your WSDL file so it can be accessed from your client.
You can generate WSDL from the IDE. But I'm not sure using Maven is the right way. The WSDL is your contract, it may be the one you based your WS on. The generation with IDE is just a way to make your life easier but at the end the WSDL may not change a lot. If it does then maybe SOAP is not what you need. REST may be more "agile".
Look at these links for manually generation with IDE (IntelliJ, Eclipse) or with external tool WSGEN.

WSDL: would you write it or generate it?

I know that there are two ways of creating web services:
Write wsdl first and generate java interface using web services tools like wsdl2java
Write java code first and then use tool to generate wsdl.
For me, the first method looks complex and second looks quite easy relatively. If so, I want to know
When is the first method used? Give me scenario where the first method is preferred over second.
What is the advantage of first method over second?
Which is the method which is widely used in industry for application programming?
If I am looking for a job in web services development, is it necessary for me to know how to write wsdl file for given requirements.
Sometimes you need to declare the interface upfront before you have any implementation - for example you might have to negotiate it with the customer so that he can start coding against it ASAP. Then you start with WSDL.
If you don't need to have a WSDL representation as early as possible you can follow whatever procedure is convenient for you. For example, if you develop an ASP.NET web service it's quite convenient to just write C# code and have the runtime to generate the WSDL on consumer request.

generate WSDL from java WS

Given a public SOAP web service and no WSDL, I need to build a .NET client that can communicate with this service.
I'm a .NET dev looking for a simple way to generate a WSDL file given this url? I'd prefer to do this with some tool directly from my windows development machine but the only thing I've found is the javatowsdl tool in Apache CXF or Axis2. Are there any tools (commercial or otherwise) that would accomplish this? I'm really hoping not to write my own WSDL by hand.
If I have to go the route of the javatowsdl, can this tool be used without having to setup a server to run apache/tomcat, etc? anyone know the steps necessary to actually make this work?
Update: This KB describes generating a proxy via wsdl.exe or VS both of which I've done before. The interesting part of this KB is the part at the top where it mentions using the WSTK from IBM to GET the WSDL in the first place. The WSTK no longer exists and I'm looking for alternatives. http://support.microsoft.com/kb/307324 Hope that helps to clarify things a little.
I didn't see this mentioned, but have you tried appending '?wsdl' to the end of the soap url and trying it out in a browser?
Say for example the url to the service is http://www.someserver.com/service/NewService. Then you could try this in any web browser and see if it works
http://www.someserver.com/service/NewService?wsdl
If the browser pulls up the wsdl, than you can also the same url to wsdl.exe and it will generate the .NET client stubs for you.
Supposing you are using Visual Studio, right click your project and click Add Web Reference. Then enter the end point URL and you should do fine from here. Further details here.
Not sure what you actually want to create the WSDL from...? You say this is about a public SOAP service without WSDL - which means that this service does NOT offer a WSDL by itself already, right?
So what do you know exactly about this service then? Because, if you only know the URL of where to invoke the service without any additional specification (and again, if the service does NOT publish it's WSDL itself already, like on the same URL with an appended ?wsdl), I guess you don't really have any basis to create something from.
So some more info required here I guess...
The usage for Java2WSDL is explained here. It requires Java classes or interfaces describing the web service for it to do the translation (i.e. you can't just give it a SOAP request/response and hope it'll work it out from there). WSDL2Java can generate Java client-side bindings when given a WSDL (which is probably useless if you want to write a .NET web service client). All of this can be done without running a Java application server (because you're not actually hosting the web service, you're just describing its inputs and outputs).
Therefore, if you wanted to go down this path, what you'd have to do is work out the server-side interfaces in Java, and use Java2WSDL to generate the WSDL. From there, you can feed the WSDL into Visual Studio as per the KB article you linked.
I can promise you now that it will be fiddly getting the interfaces correct. Regardless of whether you can get the inputs and outputs correct, there's still the matter of Document vs. RPC and all kinds of other parameters that might not be readily apparent from looking at SOAP requests/responses.
whoAfter lots of reading and research, I found this little gem: http://wscfblue.codeplex.com/ It took the XSD and generated a WSDL file and can also generate the proxy code if you choose. I don't have everything working end to end yet but I thought I'd go ahead a post this for anyone else you might have a similar question. If I remember, I'll post back any notes on this once I'm done.

Is there an efficient tool to convert the .Net C# webservice to java webservice?

Is there an efficient tool to convert the .Net C# webservice to java webservice. Is there any open source tool that can help?
Don't waste your time looking for a transition tool. If you were working with Java 1.4 and maybe C# 1.x, there was a beta utility from Microsoft that did on-par conversion between the two. But that was a long time ago, and they don't publish the utility any longer. Even then, the utility would only convert source code at the language level, as opposed to dealing with the separate languages' implementation, i.e. in a Windows service, web service, console app, etc.
Having ported applications in both directions (C#->Java and Java->C#), the manual effort IS your shortest path. Any tool that suggests otherwise is likely a poor implementation. You're making modifications in either case. Convert-and-update is slower than writing-from-scratch.
Not to suggest this, but if the basis for your approach is not time-savings but rather a lack of understanding C#, then a conversion tool is only going to cause you more problems because it will hide the true intention of the source code.
Basically, take your lumps and roll your own. Follow #Padmarag's suggestion and stick with simplicity. The closest agreement between your two options (C# and Java) is a generated WSDL. This is a great way to get started with your base objects and operations.
I have never tried this, but maybe you could try to make a contract first web service in java with the wsdl of the c# web service.
A simple option would be to -
create Web - Service in .Net
Generate the WSDL
Copy the WSDL to Java Project (possibly in Netbeans/ Eclipse)
Implement the WSDL using reverse engineering - also called as "Start with WSDL" approach.
Implement the generated methods.
Check this out:
http://www.cs2j.com/

Quickstart tool for Spring-Webservices?

Now, working with Spring-WS, I sometimes miss the simplicity of working with axis, where you just call a tool on the WSDL and XSD, and it creates the java objects and marshaller configurations, an interface that represents the information in the WSDL, a complete webservice client that implements this interface, and a server stub. Within minutes you can start writing the actual code for the webservice.
With Spring-WS you have much more configuration work to do - you have configure a marshaller, an endpoint, code all the information in the WSDL manually, and using the soap faults from the WSDL in form of java Exceptions seems difficult. Is there any tool that simplifies this work to a similar degree? I understand and appreciate that Spring-WS is flexible and whatnot, but sometimes you just want to whip up a quick webservice.
If you want the quick-and-easy tooled approach, then Spring-WS is not for you. It emphasises flexibility, small footprint and runtime simplicity, at the expense of having a bit more to do at first.
If this isn't what you want, then stick with the more heavyweight stacks like CXF or Axis2.
It's explained on this page: Why Contract First?. Basically, since there are problems to be solved when starting from a WSDL, they have chosen to drop the ball. If you want to work from a WSDL and keep being integrated with Spring, then choose CXF.

Categories

Resources