Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 05:16 PM.

  • #2
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dont worry, i found the problem. It wasnt the code. The url for the webservice had changed slightly.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •