Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-22-2011, 10:35 PM   PM User | #1
andy.wallace
New to the CF scene

 
Join Date: Jul 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
andy.wallace is an unknown quantity at this point
Where an i going wrong

Hi, i know very little about Java but have a sudden need to get something working in Java. I need to consume a webservice. I have what i think should work but it just returns the HTML for the webservice page and not the XML response. This should be a simple request to a weather service where i provide the zip. Anyone know what i am doing wrong.

i am just running this by typing java RunMyCode (i get no errors)

My calling code is this:

public class RunMyCode {
public static void main(String args[]) {
SimpleSOAP soapy = new SimpleSOAP("55311");
String xml = soapy.getRequest();
System.out.println(xml);
}
}





main code:-

import java.io.*;
import java.net.*;

public class SimpleSOAP {
String zipCode;

public SimpleSOAP(String zipCode) {
this.zipCode = "zipCode";
}

public String getRequest() {
String soapResponse = "";
String soapRequestURL = "http://ws.cdyne.com/WeatherWS/Weather.asmx";
String soapRequestTXT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<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/\">\n" +
" <soap:Body>\n" +
" <GetCityWeatherByZIP xmlns=\"http://ws.cdyne.com/WeatherWS/\">\n" +
" <ZIP>" + this.zipCode + "</ZIP>" +
" </GetCityWeatherByZIP>\n" +
" </soap:Body>\n" +
"</soap:Envelope>";

try {
URL url = new URL(soapRequestURL);
URLConnection conn = url.openConnection();
conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
conn.setRequestProperty("Content-Length", "" + soapRequestTXT.length());
conn.setDoOutput(true);

OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());

wr.write(soapRequestTXT);
wr.flush();

BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));

String line = "";
while ((line = rd.readLine()) != null) {
soapResponse += line;
}

wr.close();
rd.close();

return soapResponse;
} catch (Exception exception) {
return "";
}

}
}

Last edited by andy.wallace; 07-23-2011 at 04:16 PM..
andy.wallace is offline   Reply With Quote
Old 07-23-2011, 04:17 PM   PM User | #2
andy.wallace
New to the CF scene

 
Join Date: Jul 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
andy.wallace is an unknown quantity at this point
Dont worry, i found the problem. It wasnt the code. The url for the webservice had changed slightly.
andy.wallace is offline   Reply With Quote
Old 07-23-2011, 09:55 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by andy.wallace View Post
Dont worry, i found the problem. It wasnt the code. The url for the webservice had changed slightly.
Awesome, than it wasn't just me O.o
Been awhile since I'd used SOAP with java myself, but I also couldn't get it to go on this site. I could however establish with other soap services, so I was also leaning towards a config issue on their end.
Interesting how they give examples of what to send them and then they don't work that way anyway.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:48 PM.


Advertisement
Log in to turn off these ads.