Frage

I have Java app that sends HTTP request to a specific port. That piece of code is something like this:

        URL url = new URL("http://localhost:8080/");
        HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
        httpCon.setDoOutput(true);
        httpCon.setRequestMethod("POST");
        OutputStreamWriter out = new OutputStreamWriter(
        httpCon.getOutputStream());
        System.out.println(httpCon.getResponseCode());
        System.out.println(httpCon.getResponseMessage());
        out.close();

Now, I'd like to create WCF service that listens to a specific port and receives HTTP POST request sent from my Java app. Is this possible and what are the guidelines to do that. I'm kinda new to WCF, I have went through few WCF examples but I need more and something more related to my problem. So, what binding should I use, behavior, ...?

Any help will be appreciated!

War es hilfreich?

Lösung

It's certainly possible to get WCF and Java running together. The WCF part you'll probably want to code in C# and implement through .NET, but the Java side is pretty easy.

There's plenty of sample code out there to choose from in implementing this, but here's a three-part series I used to get a Java - WCF project going. In included another sample from CodeProject as well.

http://geekswithblogs.net/ballhaus/archive/2009/12/28/net-wcf-and-java-ws-interoperability-part1.aspx

http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide

The binding and behavior stuff you'll have to figure out based on the requirements of the project. There are several binding flavors, including HTTP, TCP and others. The behaviors vary, too.

Here's a good single source of information for comparing the different binding types and what each offers in terms of features and compatibility.

http://msdn.microsoft.com/en-us/library/ms730879.aspx

Andere Tipps

Considering you are just starting with WCF, I would recommend that you use basicHttpBinding in WCF initially and then fine tune the binding as you learn and discover tricks of WCF. a typical basicHttpBinding will look like

<basicHttpBinding>
        <binding name="basicClientBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:02:00"   hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None"></security>
        </binding>

</basicHttpBinding> 

creating WCF proxy in Java using Axis could be a pain if the WCF uses multple bindings or even wsHttpBinding. you will find many posts like the ones below that talks about complexities of using a complex behavior or wsHttpBinding from Java

How to create java client using AXis 1.4 for consuming WCF service using wsHttpBinding

You are not using Axis or anything else to create a proxy, so it will be very tricky for you.I would recommend that in your case, start out with a vanilla WCF service with basicHttpBinding and no behavior.

Also while writing your C# service avoid using incompatible .Net types like SecureString. SecureString is the recommended type for password. but there is no equivalent mapped type in Java world

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top