Reputation: 21
I am new to Java and I need to call a WCF. Is there any way in Java that I do not need to consume it and can directly hit the url to get response?
Upvotes: 2
Views: 3038
Reputation: 1
You can make a direct call using HttpURLConnection in the Java.Net library
URL url = new URL("https://{ApiEndpoint}/v2/EmailMarketing.svc/SendEmail");
HttpURLConnection http = (HttpURLConnection)url.openConnection();
http.setRequestMethod("POST");
http.setDoOutput(true);
http.setRequestProperty("Content-Type", "application/json");
http.setRequestProperty("Accept", "application/json");
String data = "{\"Id\": 78912, \"Quantity\": 1, \"Price\": 19.00}";
byte[] out = data.getBytes(StandardCharsets.UTF_8);
OutputStream stream = http.getOutputStream();
stream.write(out);
System.out.println(http.getResponseCode() + " " +
http.getResponseMessage());
http.disconnect();
Upvotes: 0
Reputation: 1359
For Java client application, I think you can generate the proxy class from Eclipse and invoke the call to WCF service.
The general steps are as follows:
Prepare the WCF service and run the service.
Create the Java client application in Eclipse IDE, and name the project, like WCFClientApp in this case.
You can follow this blog for better practical understanding https://www.codeproject.com/Articles/777036/Consuming-WCF-Service-in-Java-Client
Upvotes: 0
Reputation: 75
You can consume the webservice using Java there are different frameworks to make your job easier, like AXIS and Apache CXF
Look at following article for more details
Consuming WCF services with Java
Upvotes: 1