Link to home
Start Free TrialLog in
Avatar of knobloch
knobloch

asked on

JAVA to C# code translation request Please

Hi
Could anyone translate this Java code to C# for me. I don't know Java and I can't find suitable methods in C# in order to make this code work.



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

/**
 * A sample program that shows how to interact with MapViewer
 */

public class MapViewerDemo {
  private HttpURLConnection mapViewer = null;



  /**
   * Initializes this demo with the URL to the MapViewer server.
   * The URL is typically http://my_corp.com:8888/mapviewer/omserver.
   */
  public MapViewerDemo(String mapViewerURLString) {
    URL url;
    try {
      url = new URL(mapViewerURLString);
      mapViewer = (HttpURLConnection) url.openConnection();
      mapViewer.setDoOutput(true);
      mapViewer.setDoInput(true);
      mapViewer.setUseCaches(false);
    }
    catch (Exception e) {
      e.printStackTrace(System.err);
      System.exit(1);
    }
  }

  /**
   * Submits an XML request to MapViewer.
   Map Request Examples
   3-12 Oracle Application Server MapViewer User’s Guide
   * @param xmlreq the XML document that is a MapViewer request
   */
  public void submitRequest(String xmlreq) {
    try {
      mapViewer.setRequestMethod("POST"); //Use HTTP POST method.
      OutputStream os = mapViewer.getOutputStream();
//MapViewer expects to find the request as a parameter
//named "xml_request".
      xmlreq = "xml_request=" + URLEncoder.encode(xmlreq);
      os.write(xmlreq.getBytes());
      os.flush();
      os.close();
    }
    catch (Exception e) {
      e.printStackTrace(System.err);
      System.exit(1);
    }
  }

  /**
   * Receives an XML response from MapViewer.
   */
  public String getResponse() {
    ByteArrayOutputStream content = new ByteArrayOutputStream();
    InputStream is = null;
    try {
      is = mapViewer.getInputStream();
      int c;
      while ( (c = is.read()) != -1) {
        content.write(c);
      }
      is.close();
      content.flush();
      content.close();
      return content.toString();
    }
    catch (Exception e) {
      e.printStackTrace(System.err);
      return null;
    }
  }

// A simple main program that sends a list_data_sources XML
// request to MapViewer through HTTP POST
 


}



Thanks
ASKER CERTIFIED SOLUTION
Avatar of Thandava Vallepalli
Thandava Vallepalli
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial