Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

JAVA to C# code translation request Please

Posted on 2005-02-28
2
Medium Priority
?
1,384 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
  • 2
2 Comments
 
LVL 14

Accepted Solution

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

571 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