?
Solved

JAVA to C# code translation request Please

Posted on 2005-02-28
2
Medium Priority
?
1,375 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:knobloch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 14

Accepted Solution

by:
Thandava Vallepalli earned 1500 total points
ID: 13426956
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question