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(fal se);
}
catch (Exception e) {
e.printStackTrace(System.e rr);
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.e rr);
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.e rr);
return null;
}
}
// A simple main program that sends a list_data_sources XML
// request to MapViewer through HTTP POST
}
Thanks
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(fal
}
catch (Exception e) {
e.printStackTrace(System.e
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
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.e
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.e
return null;
}
}
// A simple main program that sends a list_data_sources XML
// request to MapViewer through HTTP POST
}
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.csharp-station.com/HowTo/HttpWebFetch.aspx