How to reference a local WSDL file in a JAX-RPC client.
843833Jun 19 2007 — edited Jun 22 2007Greetings,
I am writing a simple service client using Java WSDP 2.0.
I already created a Web Service that is a STAND-ALONE executable. It is listening on a port. I created this service with gSoap (C++). I HAVE created and successfully tested a gSOAP client for this (of course).
However, now I am creating a Java client, and I ran Java WSDP's wscompile on the following WSDL,file, which by the way was automatically generated by gSOAP:
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="Service"
targetNamespace="http://127.0.0.1:18081/Service.wsdl"
xmlns:tns="http://127.0.0.1:18081/Service.wsdl"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://tempuri.org/ns1.xsd"
xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"
xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="http://tempuri.org/ns1.xsd"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://tempuri.org/ns1.xsd"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
</schema>
</types>
<message name="sayHelloRequest">
</message>
<message name="sayHelloResponse">
<part name="result" type="xsd:string"/>
</message>
<message name="setNumberRequest">
<part name="number" type="xsd:int"/>
</message>
<message name="setNumberResponse">
<part name="out" type="xsd:int"/>
</message>
<message name="getNumberRequest">
</message>
<message name="getNumberResponse">
<part name="intres" type="xsd:int"/>
</message>
<portType name="ServicePortType">
<operation name="sayHello">
<documentation>Service definition of function ns1__sayHello</documentation>
<input message="tns:sayHelloRequest"/>
<output message="tns:sayHelloResponse"/>
</operation>
<operation name="setNumber">
<documentation>Service definition of function ns1__setNumber</documentation>
<input message="tns:setNumberRequest"/>
<output message="tns:setNumberResponse"/>
</operation>
<operation name="getNumber">
<documentation>Service definition of function ns1__getNumber</documentation>
<input message="tns:getNumberRequest"/>
<output message="tns:getNumberResponse"/>
</operation>
</portType>
<binding name="Service" type="tns:ServicePortType">
<SOAP:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sayHello">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="http://tempuri.org/ns1.xsd" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="http://tempuri.org/ns1.xsd" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="setNumber">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="http://tempuri.org/ns1.xsd" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="http://tempuri.org/ns1.xsd" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="getNumber">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="http://tempuri.org/ns1.xsd" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="http://tempuri.org/ns1.xsd" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="Service">
<documentation>gSOAP 2.7.9f generated service definition</documentation>
<port name="Service" binding="tns:Service">
<SOAP:address location="http://127.0.0.1:18081"/>
</port>
</service>
</definitions>
Anyway, as you might observe it seems the WSDL is using the proper encoding, but when I run the client, I get the following message:
java.rmi.RemoteException: Runtime exception; nested exception is:
unexpected encoding style: expected=http://schemas.xmlsoap.org/soap/encoding/, actual=
at com.sun.xml.rpc.client.StreamingSender._handleRuntimeExceptionInSend(StreamingSender.java:331)
at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:313)
at staticstub.ServicePortType_Stub.sayHello(Unknown Source)
at staticstub.HelloClient.main(Unknown Source)
Caused by: unexpected encoding style: expected=http://schemas.xmlsoap.org/soap/encoding/, actual=
at com.sun.xml.rpc.encoding.SOAPDeserializationContext.verifyEncodingStyle(SOAPDeserializationContex
at com.sun.xml.rpc.encoding.ObjectSerializerBase.deserialize(ObjectSerializerBase.java:175)
at com.sun.xml.rpc.encoding.ReferenceableSerializerImpl.deserialize(ReferenceableSerializerImpl.java
at staticstub.ServicePortType_Stub._deserialize_sayHello(Unknown Source)
at staticstub.ServicePortType_Stub._readFirstBodyElement(Unknown Source)
at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:228)
... 2 more
With all of that said, in trying to debug the problem, I went to the stub files that WSCompile created. Inside of my service implementation class file (aply named Service_impl) it defines the service Name and Service QName as:
private static final QName serviceName = new QName("http://127.0.0.1:18081/Service.wsdl", "Service");
private static final QName ns1_Service_QNAME = new QName("http://127.0.0.1:18081/Service.wsdl", "Service")
Now when I enter the string " http://127.0.0.1:18081/Service.wsdl" in Internet Explorer, the WSDL file does NOT appear which I would not expect to (I think) but left me with the question of how then would the software know how to interpret a WSDL file it could not find. The flip side is that maybe it does not need to. In any event, if that is a problem I don't know how to reference a local wsdl file.
Lastly, when the Java Client runs, I can see that THE WEB SERVICE IS RESPONDING TO THE RIGHT REQUEST (I have 3 requests on the server). It just does not get interpreted right back at the client and thus the error message above.
So I am sort of leaning towards the idea that I need to tell the Stub code where this WSDL file is on disk so it can parse it and interpret it properly but I am not sure where I should do this nor the proper syntax.
Or maybe I am all confused and am totally thinking about this wrong (would not be the first time). In any event, any insight/help would be greatly appreciated.
Remember, my Web Service is a standalone application waiting on a port, port 18081 to be exact. My C++ client, written using the same toolkit as the web service works just fine. Unfortunately, the Java client does not.
Thanks Again,
Richard