Java connect to C#

On my java code, I am trying to connect to .Net C# web server and trying to get a response.
The java code (window client application) will post a file to this C# web server and get a success flag once it is completed, how do I start with the C# code as I am not a .Net programmer?
The java code:
 
public void transferFileToServer(String url,File localFile, String fileName) throws Exception{
		HttpURLConnection urlConn = null;
		try{
 
			URL  anUrl = new URL(url);
			urlConn = (HttpURLConnection)anUrl.openConnection();
			urlConn.setDoOutput(true);
			urlConn.setDoInput(true);
 
			urlConn.connect();
			System.out.println("Swing App url connect");
 
			DataOutputStream ps = new DataOutputStream(urlConn.getOutputStream());
            		ps.writeUTF(fileName);
 
			FileInputStream fis = new FileInputStream(localFile);
			BufferedInputStream bis = new BufferedInputStream(fis);
 
			int len = 2048;
			byte[] bytes = new byte[len];
			int index = 0;
			while(index >= 0){
				index = bis.read(bytes,0,len);
				if(index != -1){
					ps.write(bytes,0,index);
				}
			}
			fis.close();
 
			ps.flush();
			ps.close();
 
			BufferedInputStream dis = new BufferedInputStream(urlConn.getInputStream());
			bytes = new byte[len];
			while(dis.read(bytes) > 0){
				//System.out.println("bytes read :["+new String(bytes)+"]");
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		finally{
			if(urlConn != null){urlConn.disconnect();}
			System.out.println("disconnect");
		}
 
    }

Open in new window

fkchanAsked:
Who is Participating?
 
Refael AckermannCommented:
Simplest solution is to create and ASHX (ASPX.nET Generic HTTP Handler):
http://www.brainbell.com/tutorials/ASP/Generic_Handlers_(ASHX_Files).html
0
 
fkchanAuthor Commented:
Do you have sample code to read the input stream, save the file to a specific location and then return a success flag?
0
 
Refael AckermannCommented:
The Context.HttpRequest.Files holds handlers to all files posted to the server as a HttpPostedFile collection.
Then you can use the HttpPostedFile.SaveAs method to save.
And then you can use Context.HttpResponse.Write to send the response.


This seems like a popular forum-thread about these kind of issues:
http://forums.asp.net/t/55127.aspx?PageIndex=2
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.