Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

whats wrong with this ??? ASP.NET service and Java Client  RSS feed

 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i am getting the following error can someone explain why ??
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
EndpointURL: http://localhost/test/HelloWorld.asmx
Calling EchoString...
EchoString called with: This is a string
after invoking
java.lang.NullPointerException
at EchoApacheProxy.EchoString(EchoApacheProxy.java:61)
at EchoClient.main(EchoClient.java:26)
EchoString Result: null%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
To the problem directly... My SOAP file

POST /test/HelloWorld.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/test/HelloWorld/EchoString"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<EchoString xmlns="http://tempuri.org/test/HelloWorld">
<theString>string</theString>
</EchoString>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<EchoStringResponse xmlns="http://tempuri.org/test/HelloWorld">
<EchoStringResult>string</EchoStringResult>
</EchoStringResponse>
</soap:Body>
</soap:Envelope>



The Java Client...
public class EchoClient
{
public static void main(String[] args)
{
try {
// Set the SOAP EndpointURL
String sEndpointURL = "http://localhost/test/HelloWorld.asmx";
System.out.println("EndpointURL: " + sEndpointURL);
EchoApacheProxy echoProxy = new EchoApacheProxy(sEndpointURL);

// Call the EchoString method
String theString = "This is a string";
System.out.println("\nCalling EchoString...");
System.out.println("EchoString called with: " + theString);
System.out.println("EchoString Result: " + echoProxy.EchoString(theString));


}
catch(Exception e){
System.out.println(e.toString());
}
}
}

----EchoApacheProxy.java------

public class EchoApacheProxy extends BaseApacheProxy
{
protected static String METHOD_NAMESPACE = "http://tempuri.org/test/HelloWorld/";

public EchoApacheProxy(String EndpointURL ) throws MalformedURLException
{
super(EndpointURL, METHOD_NAMESPACE);
}

// This Method uses the "RPC" style of call, and corresponding Apache 2.2
// classes to do so.
public synchronized String EchoString (String theString) throws SOAPException
{ try{


if (_url == null)
{
throw new SOAPException(org.apache.soap.Constants.FAULT_CODE_CLIENT,
"A URL must be specified via setEndPoint(URL).");
}

// Map the types.
SOAPMappingRegistry smr = new SOAPMappingRegistry();
StringDeserializer ser = new StringDeserializer ();
smr.mapTypes (Constants.NS_URI_SOAP_ENC,null, String.class, null, ser);
_call.setSOAPMappingRegistry(smr);
_call.setMethodName("EchoString");
_call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
Vector params = new Vector();
Parameter pTheString = new Parameter("theString", String.class, theString, Constants.NS_URI_SOAP_ENC);
params.addElement(pTheString);
_call.setParams(params);
Response resp = _call.invoke(_url, METHOD_NAMESPACE + "EchoString");
System.out.println("after invoking");

// Check the response.
if (resp.generatedFault())
{
Fault fault = resp.getFault();
throw new SOAPException(fault.getFaultCode(), fault.getFaultString());
}
else
{
Parameter retValue = resp.getReturnValue();
----->line 61--->String theResult = (String)retValue.getValue();
return theResult;
}
}catch(Exception e){
e.printStackTrace();
return null;
}

}
}


------BaseApacheProxy------


public class BaseApacheProxy
{
protected SOAPHTTPConnection _conn;
protected Call _call;// Use for rpc/enc style calls
protected Message _msg;// Used for doc/literal (Message) style calls
protected URL _url;

public BaseApacheProxy(String EndpointURL, String methodNamespace) throws MalformedURLException
{
this._conn = new SOAPHTTPConnection();
this._call = new Call();
this._call.setSOAPTransport(this._conn);
this._call.setTargetObjectURI(methodNamespace);
this._msg = new Message();
this._msg.setSOAPTransport(this._conn);
this._url = new URL( EndpointURL );
}

public synchronized void setEndPoint(String sUrl) throws MalformedURLException
{
this._url = new URL(sUrl);
}

public synchronized String getEndPoint()
{
return _url.toString();
}

public synchronized SOAPHTTPConnection getSOAPHTTPConnection()
{
return _conn;
}

public synchronized void setSOAPHTTPConnection(SOAPHTTPConnection conn)
{
_conn = conn;
this._call.setSOAPTransport(this._conn);
this._msg.setSOAPTransport(this._conn);
}
}


all help will be appreciated...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!