DII Webservice Client failure

I

Ike

I am directly taking from the HelloClient example of DII in JAX_RPC tutorial
from Sun, and altering the values for the webservice
DOTSGeoPhone:GetPhoneInfo described at
http://ws2.serviceobjects.net/gp/GeoPhone.asmx?op=GetPhoneInfo

I am getting an "unexpected encoding style," error
when it gets to the line in code below:

String result = (String)call.invoke(params);

I encounter the following error (unexpected encoding style), which I am
trying to discern the cause of. I have enclsoed the call stack to the error,
followed by the code that is causing the problem. TIA, Ike

unexpected encoding style:
expected=http://schemas.xmlsoap.org/soap/encoding/, actual=
at
com.sun.xml.rpc.encoding.SOAPDeserializationContext.verifyEncodingStyle(SOAP
DeserializationContext.java:160)
at
com.sun.xml.rpc.encoding.ObjectSerializerBase.deserialize(ObjectSerializerBa
se.java:148)
at
com.sun.xml.rpc.encoding.ReferenceableSerializerImpl.deserialize(Referenceab
leSerializerImpl.java:141)
at
com.sun.xml.rpc.client.dii.CallInvokerImpl._readFirstBodyElement(CallInvoker
Impl.java:225)
at
com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:168)
at
com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvokerImpl.java:64)
at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:346)
at dii.HelloClient.main(HelloClient.java:162)

-----------------------
package dii;

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;

public class HelloClient {

private static String qnameService = "DOTSGeoPhone";//<service
name="InstantMessageAlert">
private static String qnamePort = "DOTSGeoPhoneSoap";//<portType
name="InstantMessageAlertSoap">

private static String BODY_NAMESPACE_VALUE = "urn:Foo";
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
endpoint="http://ws2.serviceobjects.net/gp/GeoPhone.asmx";//<soap:address>
System.out.println("Endpoint address = " + endpoint);

try {
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://www.serviceobjects.com/GetPhoneInfo" );
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,"GetContactInfo "));//the method we call

call.addParameter("PhoneNumber", QNAME_TYPE_STRING,
ParameterMode.IN);
call.addParameter("LicenseKey", QNAME_TYPE_STRING,
ParameterMode.IN);


String[] params = {"440 247 1962" ,"MyLicenseKey"};

String result = (String)call.invoke(params);
System.out.println(result);

} catch (Exception ex) {
ex.printStackTrace();
}


}
}
 
S

Steve W. Jackson

Ike said:
I am directly taking from the HelloClient example of DII in JAX_RPC tutorial
from Sun, and altering the values for the webservice
DOTSGeoPhone:GetPhoneInfo described at
http://ws2.serviceobjects.net/gp/GeoPhone.asmx?op=GetPhoneInfo

I am getting an "unexpected encoding style," error
when it gets to the line in code below:

String result = (String)call.invoke(params);

I encounter the following error (unexpected encoding style), which I am
trying to discern the cause of. I have enclsoed the call stack to the error,
followed by the code that is causing the problem. TIA, Ike

unexpected encoding style:
expected=http://schemas.xmlsoap.org/soap/encoding/, actual=
at
com.sun.xml.rpc.encoding.SOAPDeserializationContext.verifyEncodingStyle(SOAP
DeserializationContext.java:160)
at
com.sun.xml.rpc.encoding.ObjectSerializerBase.deserialize(ObjectSerializerBa
se.java:148)
at
com.sun.xml.rpc.encoding.ReferenceableSerializerImpl.deserialize(Referenceab
leSerializerImpl.java:141)
at
com.sun.xml.rpc.client.dii.CallInvokerImpl._readFirstBodyElement(CallInvoker
Impl.java:225)
at
com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:168)
at
com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvokerImpl.java:64)
at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:346)
at dii.HelloClient.main(HelloClient.java:162)

-----------------------
package dii;

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;

public class HelloClient {

private static String qnameService = "DOTSGeoPhone";//<service
name="InstantMessageAlert">
private static String qnamePort = "DOTSGeoPhoneSoap";//<portType
name="InstantMessageAlertSoap">

private static String BODY_NAMESPACE_VALUE = "urn:Foo";
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
endpoint="http://ws2.serviceobjects.net/gp/GeoPhone.asmx";//<soap:address>
System.out.println("Endpoint address = " + endpoint);

try {
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://www.serviceobjects.com/GetPhoneInfo" );
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,"GetContactInfo "));//the method we call

call.addParameter("PhoneNumber", QNAME_TYPE_STRING,
ParameterMode.IN);
call.addParameter("LicenseKey", QNAME_TYPE_STRING,
ParameterMode.IN);


String[] params = {"440 247 1962" ,"MyLicenseKey"};

String result = (String)call.invoke(params);
System.out.println(result);

} catch (Exception ex) {
ex.printStackTrace();
}


}
}

This is not going to work -- for multiple reasons.

First, note that you've still got the static namespace and encoding
values specified in your code from the examples in the tutorial, but
those aren't used by the service you're trying to invoke. You're also
setting the return type as the XSD string type, but the service does not
return that type. It returns a more complex type it calls PhoneInfo.

More importantly, however, the service you're trying to call is what's
called doc/literal. At present, JAX-RPC does not support doc/literal
calls via the DII approach. I struggled with this for quite some time
in both the JWSDP 1.3 and 1.4 installations and tutorials. I even
joined the JAX-RPC community and subscribed to the JAX-RPC mailing list
to ask. But I finally saw confirmation from a reliable Sun source that
DII doesn't do doc/lit at all (I believe they said it's supposed to be
handled in JAX-RPC 2.0). I've yet to ever get DII to work with any
service created in the form of that one, which appears to have been made
using .NET tools.

So if you want to invoke that particular service, I suggest you look
into the static stub approach. It was a little more complex to me when
I first tried getting my head around it, but it turns out not to be so
difficult to use. And it can in fact support doc/literal services. Or,
as an alternative, you may want to look into SAAJ, where you'll actually
have to learn a little more about the structure of SOAP messages. But
with it, you should be able to construct an appropriate SOAP message to
send, then deconstruct what you get back to obtain the information you
need.

= Steve =
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top