Creating client jar from a WSDL - axis2

I am supposed to consume a SOAP service exposed by a third party. I have 2 basic questions w.r.t that:
Q1. The WSDL needs a basic authentication to access through the browser. Now when I try creating the client jar using wsgen/WSDL2JAVA/ using Eclipse Webservice client, I get HTTP 401 unauthorised. If I download and save the WSDL locally and then use axis's WSDL2JAVA, I get
Exception in thread "main" org.apache.axis2.wsdl.codegen.CodeGenerationException: Error parsing WSDL
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.<init>(CodeGenerationEngine.java:178)
at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35)
at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'file:/C:/TEST/TOOLS/Authentication.wsdl'.: org.xml.sax.SAXParseException: The prefix "wsdl" for element "wsdl:definitions" is not bound.
at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.readInTheWSDLFile(CodeGenerationEngine.java:320)
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.<init>(CodeGenerationEngine.java:133)
... 2 more
Caused by: org.xml.sax.SAXParseException: The prefix "wsdl" for element "wsdl:definitions" is not bound.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
... 7 more
Q2. How do we handle a frequently changing WSDL, do we generate the client jars everytime and redeploy the application?
Any pointers in helping me create the client.jar would be great.

You should definitely redeploy your client.jar for every change in WSDL.
I would suggest you this.
Create a jar project to generate classes from wsdl. Check cxf-codegen-plugin wsdl2java for example.
Create another jar project(Client.jar) that refer the previous project.
So whenever a change in WSDL you should modify the WSDL URL in the project and then build both jar project to create Client.jar. Better practice is to use the WSDL URL as a configurable property value inside or outside the Client.jar for maintaining it.
Hope this helps.

In your wsdl file, check the "<"wsdl:definitions">" tag for the xmlns:wsdl attribute, if this is missing it will throw the error:
"org.xml.sax.SAXParseException: The prefix "wsdl" for element "wsdl:definitions" is not bound" found on line 5 of the error summary you posted.
In the example below you will see prefixes being defined by the xmlns (xml namespace) attribute:
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns1="http://org.apache.axis2/xsd"
xmlns:ns="http://pojo.service.quickstart.samples"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
targetNamespace="http://pojo.service.quickstart.samples">
Review how xml namespaces work here:
http://www.w3schools.com/xml/xml_namespaces.asp

Related

Unable to consume WSDL in Mule 4

I am using anypoint studio 7.3.1 with Mule 4.1.x. trying to load the WSDL using Web Service Consumer.
First I placed my WSDL file under src/main/resources of my project.
In Web Service Consumer, under connector configuration I selected my WSDL and at this point the mulesoft should automatically populate “Service”, “Port” and “Address”.
However that is not happening. I read somewhere that WSDL file needs to be exported to mule-artifact.json which I did, but still doesn’t work.
To make sure my WSDL is good, I was able to load the same WSDL in soapUI and was able to access the web service.
What is it that I need to do to get this working? Is there any error log that tells what’s going on? By the way, the endpoint is http so I know there is no cert issue.
the problem was due to the xsd that was referred in the WSDL. Removed that and it worked

Apache CXF Soap Client in Wildlfy

I am trying to build a SOAP Client inside a wildfly JEE App. I am using CXF directly. I generate the SOAP Client by using wsdl2java and use the Client this way:
ServicePortTypeV1 servicePortV1 = new ServiceV1().getServicePortV1();
Afterwards I am trying to call a method which doesn't work
In the end I get the following exception:
Caused by: java.lang.NullPointerException
at org.apache.cxf.transport.http.URLConnectionHTTPConduit.createConnection(URLConnectionHTTPConduit.java:104)
at org.apache.cxf.transport.http.URLConnectionHTTPConduit.setupConnection(URLConnectionHTTPConduit.java:117)
at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:497)
at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:324)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:277)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:13
It seems like the address is null. But I can't tell why? Can anyone help me please?
I found the solution. First we implemented this on a tomcat. The wsdl was "searched" by classpath relative path, which is allowed in tomcat but not in wildfly. I changed it by using the resource to open the URL for the wsdl.

Could not find endpoint element in .Config File

Good day to all,
We've encountered some configuration problem while retrieving an end point from configuration file at creating a ChannelFactory object.
Could not find endpoint element with name 'no matter service'
and contract 'no matter contract' in the ServiceModel client configuration section. This might be
because no configuration file was found for your application, or
because no endpoint element matching this name could be found in the
client element.
The usual solution at this kind of exception is to add .config file to exe that runs this code.
In this case we're running this code at com+ so i'd created dllhost.exe.config file with all the endpoints.
The intresting thing is that i'm using this service also from a client application and there my wcf platform founds the same endpoint without any problem.
Other endpoints at dllhost.exe.config working fine i think.
By the way the problematic proxy that uses this service is customised Enterprise Library code.
While debugging the code it is defenetly runs under the dllhost process.
Is there some way to find out it what config file it looks for the endpoint?
Thank you.
Well, after a few days of checking and testing we'd found out 2 ways to solve the problem:
dllhost.exe.config - should not be edited/created/updated manually,but from MSI.Probably the reason is that is is placed at system32 directory and windows blocks it.
Better way - is to create for COM+ Service Application Root Directory and place there 2 files
ServiceName.config - Contains list of endpoints
ServiceName.manifest - Contains 3 rows
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
</assembly>

Error when generating service interface from wsdl using svcutil

I'm trying to run the following command line but get an error. You can try to run the command yourself to test it, but i have placed the error i'm getting below.
svcutil /noConfig /language:C# /out:ICatalog.cs /n:*,ogc.csw.ebrim http://schemas.opengis.net/csw/2.0.2/profiles/ebrim/1.0/wsdl/2.0/csw-ebrim-interface.wsdl
I tried downloading the wsdl and modifying it a few different ways to get it work. But i haven't been able to find out what to modify to get it to work.
svcutil /noConfig /language:C# /out:ICatalog.cs /n:*,ogc.csw.ebrim http://localhost/temp/csw-ebrim-interface.wsdl
Does anyone know what i can modify to get this to generate code?
Any help would be greatly appreciated.
The error i get is:
Error: Cannot obtain Metadata from http://schemas.opengis.net/csw/2.0.2/profiles/ebrim/1.0/wsdl/2.0/csw-ebrim-interface.wsdl
If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata pu
blishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.mic
rosoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error
URI: http://schemas.opengis.net/csw/2.0.2/profiles/ebrim/1.0/wsdl/2.0/csw-ebrim-interface.wsdl
Metadata contains a reference that cannot be resolved: 'http://schemas.opengis.net/csw/2.0.2/profiles/ebrim/1.0/wsdl/2.0/csw-e
brim-interface.wsdl'.
The content type text/xml of the response message does not match the content type of the binding (application/soap+xml; charse
t=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes
of the response were: '<?xml version="1.0" encoding="UTF-8"?>
<wsd:description
targetNamespace="http://www.opengis.net/cat/wrs/1.0/wsdl"
xmlns:tns="http://www.opengis.net/cat/wrs/1.0/wsdl"
xmlns:wrs="http://www.opengis.net/cat/wrs/1.0"
xmlns:iri="http://www.opengis.net/cat/wrs/1.0/iri"
xmlns:csw="http://www.opengis.net/cat/csw/2.0.2"
xmlns:ows="http://www.opengis.net/ows"
xmlns:wsd="http://www.w3.org/ns/wsdl"
xmlns:wsdx="http://www.w3.org/ns/wsdl-extensions"
xmlns:wsoap="http://www.w3.org/ns/wsdl/soap"
xmlns:whttp="http://www.w3.org/ns/wsdl/http"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="http://www.w3.org/ns/wsdl http://www.w3.org/2007/06/wsdl/wsdl20.xsd
http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema.xsd">
<wsd:documentation>
W3C WSDL interface descriptions for the CSW-ebRIM 1.0 catalogue service. This
document shall be imported by all instance-specific service descriptions.
</wsd:documentation>
<w'.
HTTP GET Error
URI: http://schemas.opengis.net/csw/2.0.2/profiles/ebrim/1.0/wsdl/2.0/csw-ebrim-interface.wsdl
The document at the url http://schemas.opengis.net/csw/2.0.2/profiles/ebrim/1.0/wsdl/2.0/csw-ebrim-interface.wsdl was not reco
gnized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'XML Schema' is 'The root element of a W3C XML Schema should be <schema> and its namespace should be 'http://www.w3.
org/2001/XMLSchema'.'.
- Report from 'DISCO Document' is 'Discovery document at the URL http://schemas.opengis.net/csw/2.0.2/profiles/ebrim/1.0/wsdl/2.0/
csw-ebrim-interface.wsdl could not be found.'.
- The document format is not recognized.
- Report from 'WSDL Document' is 'There is an error in XML document (2, 2).'.
- <description xmlns='http://www.w3.org/ns/wsdl'> was not expected.

How to Create WCF proxy class given wsdl file

I have wsdl file with me.But i don't have access to the file where it is deployed.
I need to generate proxy class using the WSDl file. I am getting error while using svcutil.ece to generate proxy file
Error: Cannot import wsdl:port Detail:
Cannot find definition for
http://www.cii.com/Soa/Foundation:Basi
cHttp. Service Description with
namespace
htt://www.cii.com/Soa/Foundat ion is
missing. Parameter name: name XPath to
Error Source:
//wsdl:definitions[#targetNamespace='http://www.cii.com/Soa/Foundation/MessageDefinition.xsd']/wsdl:service[#name='CareerServicesS
ervice']/wsdl:port[#name='BasicHttp']
Thanks,
Shodhan
If you are using svcutil with a locally downloaded WSDL file, you need to also download all related XSD files and pass them on the svcutil command line as well. A great tool for automatically downloading all related XSD files is disco.exe in the Windows / .NET SDK (and there may be a svcutil mode that does it as well, don't remember for sure).