Hi,
Wrote a simple .NET web service (the classic "hello xxx" example), which takes a string and returns "hello string".
Next I wrote a jaxrpc dynamic client trying to invoke the WS, but I get a RemoteException error:
E:\MyProjects\RolesWS>ant run-client
Buildfile: build.xml
compile-client:
[javac] Compiling 1 source file to E:\MyProjects\RolesWS\dist\client
run-client:
[java] java.rmi.RemoteException: Runtime exception; nested exception is:
[java] unexpected encoding style: expected=
http://schemas.xmlsoap.org/s
oap/encoding/, actual=
[java] at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.
java:227)
[java] at com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvok
erImpl.java:54)
[java] at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:25
9)
[java] at rolesws.RolesClient.main(Unknown Source)
[java] Caused by: unexpected encoding style: expected=
http://schemas.xmlsoa
p.org/soap/encoding/, actual=
[java] at com.sun.xml.rpc.encoding.SOAPDeserializationContext.verifyEnc
odingStyle(SOAPDeserializationContext.java:142)
[java] at com.sun.xml.rpc.encoding.ObjectSerializerBase.deserialize(Obj
ectSerializerBase.java:146)
[java] at com.sun.xml.rpc.encoding.ReferenceableSerializerImpl.deserial
ize(ReferenceableSerializerImpl.java:115)
[java] at com.sun.xml.rpc.client.dii.CallInvokerImpl._readFirstBodyElem
ent(CallInvokerImpl.java:147)
[java] at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.
java:164)
[java] ... 3 more
BUILD SUCCESSFUL
Total time: 15 seconds
E:\MyProjects\RolesWS>
CLient code as follows:
package rolesws;
import javax.xml.rpc.Call;
import javax.xml.rpc.Service;
import javax.xml.rpc.JAXRPCException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.holders.*;
public class RolesClient
{
private static String qnameService = "Service1";
private static String qnamePort = "Service1Soap";
private static String BODY_NAMESPACE_VALUE =
"
http://tempuri.org/";
private static String ENCODING_STYLE_PROPERTY =
"javax.xml.rpc.encodingstyle.namespace.uri";
private static String NS_XSD =
"
http://www.w3.org/2001/XMLSchema";
private static String URI_ENCODING =
"
http://schemas.xmlsoap.org/soap/encoding/";
public static void main(String[] args)
{
String result = "";
try
{
String endpoint = "
http://localhost/DAWebService/Service1.asmx";
ServiceFactory factory = ServiceFactory.newInstance();
Service service = factory.createService(new QName(qnameService));
QName port = new QName(qnamePort);
Call call = service.createCall(port);
call.setTargetEndpointAddress(endpoint);
call.setProperty(Call.SOAPACTION_USE_PROPERTY,
new Boolean(true));
call.setProperty(Call.SOAPACTION_URI_PROPERTY, "
http://tempuri.org/HelloWorld");
call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);
QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
call.setReturnType(QNAME_TYPE_STRING);
call.setOperationName(new QName(BODY_NAMESPACE_VALUE,
"HelloWorld"));
call.addParameter("String_1", QNAME_TYPE_STRING,
ParameterMode.IN);
// invoke the call
String[] params = {"real"};
result = (String)call.invoke(params);
System.out.println(result);
} catch (Exception ex) {
ex.printStackTrace();
System.out.println(result);
}
}
}
Following is the trace of the conversation:
POST /DAWebService/Service1.asmx HTTP 1.1
Content-Type: text/xml; charset="utf-8"
Content-Length: 476
SOAPAction: "
http://tempuri.org/HelloWorld"
User-Agent: Java1.4.0_01
Host: localhost
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="
http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="
http://www.w3.org/2001/XMLSchema" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="
http://schemas.xmlsoap.org/soap/encoding/" env:encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/">
<env:Body>
<ans1:HelloWorld xmlns:ans1="
http://tempuri.org/">
<String_1 xsi:type="xsd:string">real</String_1></ans1:HelloWorld></env:Body></env:Envelope>
HTTP/1.1 100 Continue
Server: Microsoft-IIS/5.0\r\nDate: Thu, 07 Nov 2002 15:41:57 GMT
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Thu, 07 Nov 2002 15:41:57 GMT
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8\r\nContent-Length: 364
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema">
<soap:Body><HelloWorldResponse xmlns="
http://tempuri.org/">
<HelloWorldResult>Hello World</HelloWorldResult>
</HelloWorldResponse></soap:Body></soap:Envelope>
Anyone any idea what's going on?
Thanks.
Luc