GWT and ASP.NET Can Work Together: a Proxy To Connect .NET and Java
GWT is primarily used in the Java world for obvious reasons: apart from being an excellent tool for creating RIAs (indeed it's my favorite one), it allows to develop both the server and the client part using a single language and a single IDE, and it even allows to share classes.
Unfortunately, there's no easy solution to class sharing between ASP.NET and GWT, although it should be quite easy to write a code generator that creates POCOs and POJOs with the same properties and keep them synchronized. Alternatively, JSON can be used to transfer data.
In Visual Studio, open the PROJECT_HOME/war as a web site. In Eclipse, import the whole project (you must install the Google Plugin for Eclipse).
To use Ant or NetBeans, download the GWT SDK and unpack it into a "gwt" folder inside the project, so that its JARS are available at PROJECT_HOME/gwt/*.jar. If you have GWT elsewhere, customize build.xml or the NetBeans project to adjust paths accordingly.
Before starting the GWT development mode, start the ASP.NET development server and modify web.xml to match your setup (you can also use IIS). Then run the development mode and connect to: http://127.0.0.1:8888/default.aspx?gwt.codesvr=127.0.0.1:9997.
Let me highlight some features of this setup:
- the whole thing must be seen as a Java project, while the war folder can be opened as a web site in Visual Studio;
- you can customize any aspect of the war folder as a regular Visual Studio web site project;
- when you want to publish your application to the server, you must GWT-compile your Java code, then publish the war folder only;
- the Java proxy allows to redirect GET and POST calls, preserving all headers, hence cookies, hence sessions (this is shown in the sample project);
- GWT can be included in aspx pages, so GWT host pages can be generated dinamically;
- if you get a java.net.ConnectException: Connection refused: connect when running GWT, it means that the ASP.NET server has stopped, or the web.xml has not been customized correctly (see the included README).
Let me know if this setup works for you. I'll show it to my colleagues and I hope to convince them to use GWT in some serious application. There is a project that should be start soon and that would be a perfect chance, and that's why I explored this opportunity.
Update: I uploaded a video on YouTube to show how the sample project is run.
May 3, 2010 8:11 AM
Oh! thank God finally I found the person who have same idea. I already pick and run your project. Its fine but in the second page that you ask us to fill in a GWT field and press the button "Get Server info" I already did but nothing happen. Is it a problem or this project is just a sample for us to get an idea? (personally this just an example I think)a
However thank you very much for your sample project. It is a very good illustration :)
May 3, 2010 9:35 AM
it should work: when you hit "Get Server Info", you should get a popup. Please check that you modified the web.xml since you must match the port used by the ASP.NET development server.
May 7, 2010 9:03 AM
Well, now I already fix web.xml to my corresponse port which auto generate by visual studio and then I run the project in eclipse but it not work and it give me this error instead
HTTP ERROR: 500
May 7, 2010 12:54 PM
first of all make sure that your Visual Studio dev server is running (you can also use IIS if you want), then connect to the *Java* server, not to the VS one. If you are getting a 500 response from the Java server, you must look at its log to see what caused it.
Jun 3, 2010 2:48 AM
I actually did something deeper. Replaced the GWT-RPC with JSON-RPC and am now interfacing with a .net library on the IIS7 side with the GWT client.
This method requires zero changes to the GWT client and no forwarding at all.
Oct 27, 2010 11:56 AM
I'm developing with .net and gwt for two years or more.
I'm using IIS. My gwt host page is server with IIS and i tell gwt dev mode to open that host page served by IIS (no server gwt option).
I'm using JSON RPC. On client using JSON support from GWT and JayRock on server.
I find easy to dev gwt with .net. No proxy, no problems, etc... only happy coding.
Oct 27, 2010 5:25 PM
I think that the proxy is even more "transparent": you use Visual Studio and Eclipse just like you're used to. It's just a class that works behind the scenes and allows you to work without any trick.