I want to generate server code for a device like Camera. There is a standard protocol for these device called ONVIF which publish some popular WSDL documents. So I must generate an interface and skelton from ONFIV's WSDL documents.
When I use wsdl2java to generate server code from ONVIF wsdl file, it says:
org.apache.axis2.AxisFault: No services found in the WSDL at https://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl with targetnamespace http://www.onvif.org/ver10/device/wsdl
Is there a problem via these WSDL files?
How can generate Server code based on ONVIF WSDL?
I had a same problem in generating java classes from WSDL files in order to create ONVIF web server. After a great deal of investigation I found out there are some errors in WDSL files which I got form https://www.onvif.org
If you want to create java classes properly you need to make some changes on them.
First, in each .wsdl file check the correct path of schemaLocation , it may need to change to : schemaLocation="../../../ver10/schema/onvif.xsd"/>
And also check whether all .wsdl files have service tag like this.
<wsdl:service name="DeviceIOPService">
<wsdl:port name="DeviceIOPort" binding="tmd:DeviceIOBinding">
<soap:address location="http://www.onvif.org/ver10/deviceIO/wsdl"/>
</wsdl:port>
</wsdl:service>
If they don't have , create for them, then run generating command.
If you need further information, inform me.
If you go the link https://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl as you specified for wsdl2java you hit a HTML page you are not getting a WSDL file. See the screenshot below:
The HTML document is actually a valid WSDL i.e. full xml document but it uses a XSLT to transform the XML to HTML for display and this creates a bit of problem for wsdl#java.
If you view the web page source and you remove the XSLT link code:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../../../ver20/util/onvif-wsdl-viewer.xsl"?>
Becomes:
<?xml version="1.0" encoding="utf-8"?>
Then you can load the WSDL into a WSDL editor and see the operations see screen shot below:
To get this working I would contact the Onvif group and ask them for the WSDL location as the WSDL contains links to XSD files which you will need as well. The current location cannot be used as is.
Related
I have followed contract first approach. So I first wrote the wsdl file and then generated the server side code. But when I hit the url for my web service in the browser then I see the auto generated wsdl file; not the one I had kept inside META-INF folder. I have also set useOriginalwsdl=true in my services.xml file. When I try to view the wsdl in browser, it fires error
Unable to generate WSDL 1.1 for this service in description section and
If you wish Axis2 to automatically generate the WSDL 1.1, then please set useOriginalwsdl as false in your services.xml in the reason section of error tag.
Please help me.
useOriginalwsdl=true will work if you have followed the following steps:
put the custom wsdl file inside the META-INF folder.
the service name should be the same in both the custom wsdl as well as in the services.xml
Name the custome wsdl as service.wsdl or (Your ServiceName).wsdl.
Set useOriginalwsdl=true in services.xml file
Note: If useOriginalwsdl=true, Axis2 engine first tries to use any wsdl file named service.wsdl. If not found, then it tries to find named (your service name).wsdl
If not succeeds, then it shows error when u try to access the web service.
Do you have external schema references in your WSDL..? If so, those should be also added to META-INF directory... Please also attach your WSDL..
Since you are using contract first, better you validate your WSDL too.. there are wsdl validating tools available...
Thanks...
I'm consuming a webservice where the WSDL file contains imports to other wsdl and xsd schemas, e.g:
<import namespace="http://my.api.com/" location="http://other.server.com:8888/context/services/MyService?wsdl=1"/>
which in turn can import other files
<xsd:import namespace="http://my.api.com/" schemaLocation="http://other.server.com:8888/context/services/MyService?xsd=1"/>
The client is generated by cxf with a maven plugin. The main WSDL file is added as a classpath resource. However, at runtime it appears that the client actually needs access to other.server.com:8888 to resolve the WSDL completely. So the question is, does a tool exist for importing and resolving all URLs in a WSDL so that it is not dependent absolute server URLs in other imports in the WSDL, and suitable for including in a client project?
We do not control the WSDL, so we can't change it in the source.
Edit: Looking for a tool that works on Linux
Check the ServiceModel Metadata Utility Tool (Svcutil.exe) from Windows SDK.
svcutil /t:metadata http://service/metadataEndpoint
This tool locates or discovers, one or more related documents that describe a particular XML Web service using the Web Services Description Language (WSDL).
I don't know if I understood your question correctly. I'm having my battles with Jax-ws/SOAP too. :)
If you need to generate the java classes needed to call the webservice you can use Apache CXF. Inside it you have a wsdl2java. You can use it on linux.
Another option in Java SDK, on the bin folder there's the wsimport that you can use it too.
Edit: You can change the final URL at runtime using the Service class created by Apache CXF.
new SomeRandomJaxWSService(new URL(wsdl),new QName(namespace, serviceName))
I am trying to run a service in a server. But when I run it, it throws the exception below:
javax.wsdl.WSDLException: WSDLException (at /soapenv:Envelope): faultCode=INVALID_WSDL: Expected element '{http://schemas.xmlsoap.org/wsdl/}definitions'.
at com.ibm.wsdl.xml.WSDLReaderImpl.checkElementName(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.parseDefinitions(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:229)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:179)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:91)
Where do I need to put our WSDL file in our project? I have generated the WSDL to Java client code and imported it to my project. In a separate folder, I imported my all WSDL files.
In my case the problem was that I was trying to access the WS in the client using a URL like http://foo.bar/ws/WSName and I needed to use one like http://foo.bar/ws/WSName?WSDL (notice the &WSDL part).
Hope this helps someone.
It looks like your WSDL is not valid. As Andrzej Doyle said, your WSDL might be missing the element or if your WSDL has that element then it contains wrong information. It should look like...
<definitions name="HelloService"
targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
</definitions>
does your targetnamespace tag contain the correct location of wsdl??
You can get more information from
how-can-i-make-this-a-valid-wsdl and
wsdl-soap-test-with-soapui
Note: In any case, you have to correct your wsdl. So, please make sure that you have changed your wsdl in both places (In actual wsdl and in your separate folder)
As the exception states, your WSDL is invalid.
I would hazard a guess that you haven't included a <definitions> element where one was expected/required. But in any case, you need to fix up the WSDL with which you're defining the service.
I have one final hurdle to get over with the web services application I am working with; I need to be able to override the default settings used to set the schema location and soap address location in the generated WSDL file.
When I deploy the application (GlassFish v2.1 on Red Hat linux) it uses the local server name in the URLs but it needs to use the public domain name instead. I was able to save the WSDL file locally, change the URLs, make it public, generate a test application externally from the file, and lastly was able to successfully run a test.
I have now journeyed into the realm of JAX-WS custom bindings but I'm hoping that I either overlooked a simpler solution or the bindings are not as complicated as they look at first glance. The web service implementation is through a stateless EJB (e.g. MyWS.java below). The generated WSDL file would look like MyWSDL.wsdl (see below).
In the xsd:import tag I need to change schemaLocation to
http://test.mycompany.com/MyWSService/MyWS?xsd=1
instead of
http://local-server-name/MyWSService/MyWS?xsd=1
and in the soap:address tag I need to change location to be
http://test.mycompany.com/MyWSService/MyWS
instead of
http://local-server-name/MyWSService/MyWS.
MyWS.java
#WebService(name="MyWS",
portName="MyWSPort",
serviceName="MyWSService",
targetNamespace="http://test.mycompany.com/")
#Stateless()
public class MyWS {
#WebMethod(operationName="testLogin")
public String testLogin(#WebParam(name="username") String username,
#WebParam(name="password") String password) {
String retVal = "Test Failed.";
//do some stuff
return retVal;
}
...
}
MyWSDL.wsdl
<definitions targetNamespace="http://test.mycompany.com/" name="MyWSService">
<types>
<xsd:schema>
<xsd:import namespace="http://test.mycompany.com/" schemaLocation="http://local-server-name/MyWSService/MyWS?xsd=1"/>
</xsd:schema>
</types>
<service name="MyWSService">
<port name="MyWSPort" binding="tns:MyWSPortBinding">
<soap:address location="http://local-server-name/MyWSService/MyWS"/>
</port>
</service>
</definitions>
I was able to resolve the issue by changing the configuration of the GlassFish HTTP Service. I set the server's alias name to test.mycompany.com:80 for the HTTP listener being used for the web services application. Typically we have this kind of configuration in our web servers so initially I didn't even consider the application server configuration.
How are you generating the WSDL? Are you generating it by hand? Are you generating it using wsgen with the -wsdl option?
If you're deploying with JAX-WS you shouldn't actually have to do either of those things. Instead you should be able to go to...
<SERVER_URL>/<CONTEXT_LOCATION>/<SERVLET_URL>?wsdl
...and the JAX-WS servlet will automatically generate a wsdl on the fly with the correct location.
I am hosting a webservice and a webapp on the same server, generated from wsdl2java. I can contact the service just fine through SoapUI and it returns a single namespace declaration when posted to the live server, but when I am working locally and use SoapUI it generates two instances of xlmns="" instead of a single one in my xml. I have copied below an example xml file:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body>
<SendResponse xmlns="http://myendpoint.org/service" xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<Receipt>
<MyReceipt xmlns:ns3="http://myendpoint.org/service" xmlns="" xmlns="" xmlns:ns6="http://myapp.myserver.net/myservicegroup/myservice/V01" receiptVersion="V01">
<ReceiptHeader>
<ReceiptTimestamp>2010-04-13T08:27:03.036-04:00</ReceiptTimestamp>
</ReceiptHeader>
<TransmissionReceipt>
<TransmissionID>testuser</TransmissionID>
<TransmissionTimestamp>2010-04-13T08:27:03.036-04:00</TransmissionTimestamp>
</TransmissionReceipt>
</MyReceipt></Receipt></SendResponse></soap:Body></soap:Envelope>
So when it unmarshalls, it fails badly when I use my webapp as a webservice client. Why is CXF adding a second namespace? I watched the debug all the way through until the return and it looked 100% perfect on the webservice side, no duplicate name space at all. It does not happen until the return of the xml to the client side.
In XML, attributes are unique to each element, so if this occurs then it is probably a bug and you should report it as such. I've worked with CXF before and it's a great library, but it's unfortunately not perfect. I had to mess around with various versions, upgrading to an unstable one to get around the bugs I encountered.
W3C XML Spec
An attribute name MUST NOT appear more than once in the same start-tag or empty-element tag.