Introduction
We know that .NET and Java are the two different platforms. Hence, in some cases, the Java Application wants to consume the .NET WCF Service.
Even I came across the same thing, so I hope this article may help you.
Please make sure of the datatype compatibility between both Java & .NET.(Example data table type is specific for .NET, and it won't be accepted by JAVA).
Create a class library project add System.ServiceModel library to the References.
Create a Class Library Project
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.ServiceModel;
- namespace WcfService {
- [ServiceContract]
- public interface ISampleService {
- [OperationContract]
- string Message();
- }
- public class SampleService: ISampleService {
- public string Message() {
- return ".NET Web Service";
- }
- }
- }
Create Host Application for the Service
- Add System.ServiceModel library to the References.

- Add a reference to the created Class Library Project, given above.

- Create an Application Configuration file.
- < configuration > < system.serviceModel > < services > < service name = "WcfService.SampleService"
- behaviorConfiguration = "servicebehavior" > < endpoint address = ""
- binding = "basicHttpBinding"
- contract = "WcfService.ISampleService"
- bindingConfiguration = "basicbinding" > < /endpoint><endpoint address="mex"binding="mexHttpBinding"contract="IMetadataExchange"></endpoint > < host > < baseAddresses > < add baseAddress = "http://localhost:8080/SampleService" / > < /baseAddresses></host > < /service></services > < behaviors > < serviceBehaviors > < behavior name = "servicebehavior" > < serviceMetadata httpGetEnabled = "true" / > < /behavior></serviceBehaviors > < /behaviors></system.serviceModel > < /configuration>
- Create an Instance for ServiceHost Class to host the Service.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.ServiceModel;
- using WcfService;
- namespace SampleServiceHost {
- class Program {
- static void Main(string[] args) {
- ServiceHost hostobj = new ServiceHost(typeof(WcfService.SampleService));
- hostobj.Open();
- Console.WriteLine("Service Started");
- Console.Read();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.ServiceModel;
- using WcfService;
- namespace SampleServiceHost {
- class Program {
- static void Main(string[] args) {
- ServiceHost hostobj = new ServiceHost(typeof(WcfService.SampleService));
- hostobj.Open();
- Console.WriteLine("Service Started");
- Console.Read();
- }
- }
- }










Manish JainPosted Aug 26, 2019, 1:17 AM
Nice.Very simple and easy way of explanation. Thank you so much!
limPosted Oct 23, 2016, 2:13 AM
Hi. Can kindly help to elaborate what data types incompatiablity i should take note of when consuming .NET web service with Java client? Thanks!
SubashPosted Sep 15, 2016, 12:31 AM
Useful one