You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@ws.apache.org by Gaytri Thange <Ga...@Netdecisions.com> on 2002/08/09 14:06:18 UTC

need your help for trying to understand the error while invoking a webservice method from a client

Hi! 
I am writing an Apache SOAP client to acces a webservice. 
I was able to execute a sample client provided for a CurrencyExchange
webservice available on www.xmethods.com <http://www.xmethods.com>. But have
some problems coding & executing a client for the CurrencyConvertor
available on the same site. 
Below are the lines coded to invoke a method on it: 
URL url = new URL("<http://www.webservicex.net/CurrencyConvertor.asmx>"); 
Call call = new Call ();
double rate=0; Gaytri Thange | Software Engineer | netdecisions
> Mumbai Software Development Centre
6th Floor, MET Building, Gen. A K Vaidya Chowk, 
Bandra Reclamation, Mumbai 400050, India
> t +91 (0)22 644 0000   f +91 (0)22 655 8048
www.netdecisions.com
gaytri.thange@netdecisions.com

SOAPHTTPConnection con = new SOAPHTTPConnection();
con.setProxyHost("10.9.64.9");
con.setProxyPort(8080);
call.setSOAPTransport(con); 

call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setTargetObjectURI("urn:webserviceX-CurrencyConvertor");
call.setMethodName("ConversionRate"); 
Vector params = new Vector ();
params.addElement (new Parameter("fromCurrency", String.class, fromCurrency
, null));
params.addElement (new Parameter("toCurrency", String.class, toCurrency,
null));
call.setParams (params); 
SOAPMappingRegistry smr = new SOAPMappingRegistry ();
Deserializer sd1 = new XMLParameterSerializer();
smr.mapTypes (Constants.NS_URI_SOAP_ENC,
new QName ("", "fromCurrency"), String.class, null, sd1);
smr.mapTypes (Constants.NS_URI_SOAP_ENC,
new QName ("", "toCurrency"), String.class, null, sd1);
call.setSOAPMappingRegistry(smr); 
System.out.println("invoke the method call");
Response resp =
call.invoke(url,"<http://www.webserviceX.NET/ConversionRate>");
System.out.println("response received");
if (resp.generatedFault()) {
Fault fault=resp.getFault();
System.out.println(" Fault code: " + fault.getFaultCode());
System.out.println(" Fault string: "+fault.getFaultString());
} else {
Parameter result=resp.getReturnValue();
Double value = (Double)result.getValue();
rate = value.doubleValue();
} 
Following is the stack trace for the exception thrown when i try to invoke
the method on the webservice: 
Fault string: System.Web.Services.Protocols.SoapException: Server was unable
to read request. ---> System.InvalidOperationException: There is an error in
XML document (5, 2). ---> System.Xml.XmlException: Invalid namespace
declaration. Line 5, position 25.
at System.Xml.XmlNSAttributeTokenInfo.FixNSNames()
at System.Xml.XmlTextReader.SetLiteralValues(XmlAttributeTokenInfo fld)
at System.Xml.XmlTextReader.SetAttributeValues()
at System.Xml.XmlTextReader.ParseElement()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlLoader.LoadChildren(XmlNode parent)
at System.Xml.XmlLoader.LoadElementNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.ReadCurrentNode(XmlDocument doc, XmlReader reader)
at System.Xml.XmlDocument.ReadNode(XmlReader reader)
at System.Xml.Serialization.XmlSerializationReader.UnknownNode(Object o)
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read2_
ConversionRate()
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest() 
Can you kindly let me know what is it that I am missing out or doing wrong. 
Thanks, 
> Gaytri Thange | Software Engineer | netdecisions
> Mumbai Software Development Centre
6th Floor, MET Building, Gen. A K Vaidya Chowk, 
Bandra Reclamation, Mumbai 400050, India
> t +91 (0)22 644 0000   f +91 (0)22 655 8048
www.netdecisions.com
gaytri.thange@netdecisions.com


Re: need your help for trying to understand the error while invoking a webservice method from a client

Posted by Scott Nichol <sn...@scottnichol.com>.
Note that I have just committed some code that will help you write Apache
SOAP clients that work with document/literal services.  The code now
includes a doclit sample that acts as a client to a public service.

What you do is basically:

1. Map the de-serializers for the return values.  This is necessary to
handle the doc/lit response.  It relies on the existing MS interop hack of
supplying the element qname rather than the element type qname.
2. Code the call and parameters like soap/rpc encoding.
3. Do call.setDocLitSerialization(true) before invoking.

Scott Nichol

----- Original Message -----
From: "Scott Nichol" <sn...@scottnichol.com>
To: <so...@xml.apache.org>
Cc: <Ga...@Netdecisions.com>
Sent: Friday, August 09, 2002 10:16 AM
Subject: Re: need your help for trying to understand the error while
invoking a webservice method from a client


Re: need your help for trying to understand the error while invoking a webservice method from a client

Posted by Scott Nichol <sn...@scottnichol.com>.
Note that I have just committed some code that will help you write Apache
SOAP clients that work with document/literal services.  The code now
includes a doclit sample that acts as a client to a public service.

What you do is basically:

1. Map the de-serializers for the return values.  This is necessary to
handle the doc/lit response.  It relies on the existing MS interop hack of
supplying the element qname rather than the element type qname.
2. Code the call and parameters like soap/rpc encoding.
3. Do call.setDocLitSerialization(true) before invoking.

Scott Nichol

----- Original Message -----
From: "Scott Nichol" <sn...@scottnichol.com>
To: <so...@xml.apache.org>
Cc: <Ga...@Netdecisions.com>
Sent: Friday, August 09, 2002 10:16 AM
Subject: Re: need your help for trying to understand the error while
invoking a webservice method from a client


>From the service WSDL, you should do

    call.setTargetObjectURI("http://www.webserviceX.NET/");

This will lead to another error, however, since the service uses
document/literal encoding.  Apache SOAP only supports rpc/encoded directly.
You can write a client to talk to the service with Apache SOAP, but you have
to create the SOAP envelope manually.  Microsoft has a HOW TO on this at
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q308466.

Scott Nichol

----- Original Message -----
From: "Gaytri Thange" <Ga...@Netdecisions.com>
To: <so...@xml.apache.org>
Sent: Friday, August 09, 2002 8:06 AM
Subject: need your help for trying to understand the error while invoking a
webservice method from a client


Hi!
I am writing an Apache SOAP client to acces a webservice.
I was able to execute a sample client provided for a CurrencyExchange
webservice available on www.xmethods.com <http://www.xmethods.com>. But have
some problems coding & executing a client for the CurrencyConvertor
available on the same site.
Below are the lines coded to invoke a method on it:
URL url = new URL("<http://www.webservicex.net/CurrencyConvertor.asmx>");
Call call = new Call ();
double rate=0; Gaytri Thange | Software Engineer | netdecisions
> Mumbai Software Development Centre
6th Floor, MET Building, Gen. A K Vaidya Chowk,
Bandra Reclamation, Mumbai 400050, India
> t +91 (0)22 644 0000   f +91 (0)22 655 8048
www.netdecisions.com
gaytri.thange@netdecisions.com

SOAPHTTPConnection con = new SOAPHTTPConnection();
con.setProxyHost("10.9.64.9");
con.setProxyPort(8080);
call.setSOAPTransport(con);

call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setTargetObjectURI("urn:webserviceX-CurrencyConvertor");
call.setMethodName("ConversionRate");
Vector params = new Vector ();
params.addElement (new Parameter("fromCurrency", String.class, fromCurrency
, null));
params.addElement (new Parameter("toCurrency", String.class, toCurrency,
null));
call.setParams (params);
SOAPMappingRegistry smr = new SOAPMappingRegistry ();
Deserializer sd1 = new XMLParameterSerializer();
smr.mapTypes (Constants.NS_URI_SOAP_ENC,
new QName ("", "fromCurrency"), String.class, null, sd1);
smr.mapTypes (Constants.NS_URI_SOAP_ENC,
new QName ("", "toCurrency"), String.class, null, sd1);
call.setSOAPMappingRegistry(smr);
System.out.println("invoke the method call");
Response resp =
call.invoke(url,"<http://www.webserviceX.NET/ConversionRate>");
System.out.println("response received");
if (resp.generatedFault()) {
Fault fault=resp.getFault();
System.out.println(" Fault code: " + fault.getFaultCode());
System.out.println(" Fault string: "+fault.getFaultString());
} else {
Parameter result=resp.getReturnValue();
Double value = (Double)result.getValue();
rate = value.doubleValue();
}
Following is the stack trace for the exception thrown when i try to invoke
the method on the webservice:
Fault string: System.Web.Services.Protocols.SoapException: Server was unable
to read request. ---> System.InvalidOperationException: There is an error in
XML document (5, 2). ---> System.Xml.XmlException: Invalid namespace
declaration. Line 5, position 25.
at System.Xml.XmlNSAttributeTokenInfo.FixNSNames()
at System.Xml.XmlTextReader.SetLiteralValues(XmlAttributeTokenInfo fld)
at System.Xml.XmlTextReader.SetAttributeValues()
at System.Xml.XmlTextReader.ParseElement()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlLoader.LoadChildren(XmlNode parent)
at System.Xml.XmlLoader.LoadElementNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.ReadCurrentNode(XmlDocument doc, XmlReader reader)
at System.Xml.XmlDocument.ReadNode(XmlReader reader)
at System.Xml.Serialization.XmlSerializationReader.UnknownNode(Object o)
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read2_
ConversionRate()
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
Can you kindly let me know what is it that I am missing out or doing wrong.
Thanks,
> Gaytri Thange | Software Engineer | netdecisions
> Mumbai Software Development Centre
6th Floor, MET Building, Gen. A K Vaidya Chowk,
Bandra Reclamation, Mumbai 400050, India
> t +91 (0)22 644 0000   f +91 (0)22 655 8048
www.netdecisions.com
gaytri.thange@netdecisions.com


--
To unsubscribe, e-mail:   <ma...@xml.apache.org>
For additional commands, e-mail: <ma...@xml.apache.org>




--
To unsubscribe, e-mail:   <ma...@xml.apache.org>
For additional commands, e-mail: <ma...@xml.apache.org>




--
To unsubscribe, e-mail:   <ma...@xml.apache.org>
For additional commands, e-mail: <ma...@xml.apache.org>


Re: need your help for trying to understand the error while invoking a webservice method from a client

Posted by Scott Nichol <sn...@scottnichol.com>.
>From the service WSDL, you should do

    call.setTargetObjectURI("http://www.webserviceX.NET/");

This will lead to another error, however, since the service uses
document/literal encoding.  Apache SOAP only supports rpc/encoded directly.
You can write a client to talk to the service with Apache SOAP, but you have
to create the SOAP envelope manually.  Microsoft has a HOW TO on this at
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q308466.

Scott Nichol

----- Original Message -----
From: "Gaytri Thange" <Ga...@Netdecisions.com>
To: <so...@xml.apache.org>
Sent: Friday, August 09, 2002 8:06 AM
Subject: need your help for trying to understand the error while invoking a
webservice method from a client


Hi!
I am writing an Apache SOAP client to acces a webservice.
I was able to execute a sample client provided for a CurrencyExchange
webservice available on www.xmethods.com <http://www.xmethods.com>. But have
some problems coding & executing a client for the CurrencyConvertor
available on the same site.
Below are the lines coded to invoke a method on it:
URL url = new URL("<http://www.webservicex.net/CurrencyConvertor.asmx>");
Call call = new Call ();
double rate=0; Gaytri Thange | Software Engineer | netdecisions
> Mumbai Software Development Centre
6th Floor, MET Building, Gen. A K Vaidya Chowk,
Bandra Reclamation, Mumbai 400050, India
> t +91 (0)22 644 0000   f +91 (0)22 655 8048
www.netdecisions.com
gaytri.thange@netdecisions.com

SOAPHTTPConnection con = new SOAPHTTPConnection();
con.setProxyHost("10.9.64.9");
con.setProxyPort(8080);
call.setSOAPTransport(con);

call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setTargetObjectURI("urn:webserviceX-CurrencyConvertor");
call.setMethodName("ConversionRate");
Vector params = new Vector ();
params.addElement (new Parameter("fromCurrency", String.class, fromCurrency
, null));
params.addElement (new Parameter("toCurrency", String.class, toCurrency,
null));
call.setParams (params);
SOAPMappingRegistry smr = new SOAPMappingRegistry ();
Deserializer sd1 = new XMLParameterSerializer();
smr.mapTypes (Constants.NS_URI_SOAP_ENC,
new QName ("", "fromCurrency"), String.class, null, sd1);
smr.mapTypes (Constants.NS_URI_SOAP_ENC,
new QName ("", "toCurrency"), String.class, null, sd1);
call.setSOAPMappingRegistry(smr);
System.out.println("invoke the method call");
Response resp =
call.invoke(url,"<http://www.webserviceX.NET/ConversionRate>");
System.out.println("response received");
if (resp.generatedFault()) {
Fault fault=resp.getFault();
System.out.println(" Fault code: " + fault.getFaultCode());
System.out.println(" Fault string: "+fault.getFaultString());
} else {
Parameter result=resp.getReturnValue();
Double value = (Double)result.getValue();
rate = value.doubleValue();
}
Following is the stack trace for the exception thrown when i try to invoke
the method on the webservice:
Fault string: System.Web.Services.Protocols.SoapException: Server was unable
to read request. ---> System.InvalidOperationException: There is an error in
XML document (5, 2). ---> System.Xml.XmlException: Invalid namespace
declaration. Line 5, position 25.
at System.Xml.XmlNSAttributeTokenInfo.FixNSNames()
at System.Xml.XmlTextReader.SetLiteralValues(XmlAttributeTokenInfo fld)
at System.Xml.XmlTextReader.SetAttributeValues()
at System.Xml.XmlTextReader.ParseElement()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlLoader.LoadChildren(XmlNode parent)
at System.Xml.XmlLoader.LoadElementNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.ReadCurrentNode(XmlDocument doc, XmlReader reader)
at System.Xml.XmlDocument.ReadNode(XmlReader reader)
at System.Xml.Serialization.XmlSerializationReader.UnknownNode(Object o)
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read2_
ConversionRate()
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
Can you kindly let me know what is it that I am missing out or doing wrong.
Thanks,
> Gaytri Thange | Software Engineer | netdecisions
> Mumbai Software Development Centre
6th Floor, MET Building, Gen. A K Vaidya Chowk,
Bandra Reclamation, Mumbai 400050, India
> t +91 (0)22 644 0000   f +91 (0)22 655 8048
www.netdecisions.com
gaytri.thange@netdecisions.com


--
To unsubscribe, e-mail:   <ma...@xml.apache.org>
For additional commands, e-mail: <ma...@xml.apache.org>




--
To unsubscribe, e-mail:   <ma...@xml.apache.org>
For additional commands, e-mail: <ma...@xml.apache.org>