C# .NET - how to convert the following code to c#

Asked By abinav shankar on 31-Oct-11 12:29 AM
hi i want to convert the following java code to c#

HttpPost httpPost = new HttpPost("http://www.inspire-geoportal.eu/INSPIREValidatorService/resources/validation/inspire");
//xml response: httpPost.addHeader("Accept", "application/xml");
//html response
httpPost.addHeader("Accept", "text/html");
FileBody dataFile = new FileBody(new File("yourMetadataFile.xml"));
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("dataFile", dataFile);
httpPost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
switch (statusCode) {
    //OK
    case 200:   //implement the below method to extract the response
          parseServiceResponse(response);
          break;
    //Exception was thrown
    case 400:   //implement the below method to handle the exceptions
          handleServiceException(response);
          break;
    //Internal error from the service
    default:    //implement the below method to handle errors such as internal server error
          handleServerError(response);
}
smr replied to abinav shankar on 31-Oct-11 12:34 AM
hi

The Java Language Conversion Assistant (JLCA) is a tool that provides the ability to convert Java code and library http://www.developer.com/net/csharp/article.php/2235411/Converting-Java-to-C.htm# to Microsoft Visual C# .NET. Built based on the ArtinSoft migration technology, this second version adds a number of additional features to its abilities. This includes the ability to convert code from both the client and the server. Developers will be able to convert Web as well as Windows®-based applications. Java Server Pages and Java servlets can also be converted to ASP.NET.

follow these links
http://www.developer.com/net/csharp/article.php/2235411/Converting-Java-to-C.htm
http://evain.net/blog/articles/2008/05/20/sharpen-an-open-source-java-to-c-converter
Venkat K replied to abinav shankar on 31-Oct-11 12:53 AM
Microsoft's product to help migrate Java apps to .NET is JUMP:

http://msdn.microsoft.com/vjsharp/jump/default.aspx

Translating Java code to C# code is not especially difficult, provided
you have a managed library which implements all the Java API calls you
use; then simply translating the syntax suffices, with special
provisions for some features found in Java but not C#. Octopus, one of
the best commercial translation products, does something like this:

http://www.remotesoft.com/octopus/

However, translating Java in this manner yields, essentially, a Java
program written in C#, which frankly hardly seems worthwhile.
Translating Java code to idiomatic, typical C# code is a much more
difficult process, because a real C# program would use .NET library
calls, which, as Nicholas explained, have no useful general mapping to
Java API calls, and also has a number of stylistic and algorithmic
differences that are difficult or even unfeasible to map.

Rather than translate Java to C#, a better approach may be to
use a tool such as IKVM to allow your Java classes to be accessed
directly from other C# code through the .NET Framework:

http://www.ikvm.net/index.html

Reena Jain replied to abinav shankar on 31-Oct-11 01:06 AM
Hi,

Microsoft Visual Studio 2005 provides the ability to convert projects created in Visual J++® version 6.0 or written in the Java language to Visual C#® so that you can take advantage of the .NET Framework. Java Language Conversion Assistant generates a new Visual C# project from an existing Visual J++ 6.0 project or Java-language files. The Java Language Conversion Assistant wizard makes it easy to convert your existing files.

http://msdn.microsoft.com/en-us/library/c6t6bsdk%28v=vs.80%29.aspx
http://msdn.microsoft.com/en-us/magazine/cc163422.aspx
dipa ahuja replied to abinav shankar on 31-Oct-11 01:10 AM
Download from here :

http://tangiblesoftwaresolutions.com/Demo.htm
Devil Scorpio replied to abinav shankar on 31-Oct-11 01:30 AM
Hi,
  • http://en.wikipedia.org/wiki/J_Sharp is Microsoft's Java language implementation on .NET. You can access Java libraries (up to version 1.4, anyways).

  • http://www.mono-project.com/Java also runs Java on the CLR, with access to other .NET programs.

  • Microsoft Visual Studio 2005 comes with a "Java language conversion assistant" that converts Java programs to C# programs automatically for you.