Angelia
Angelia

Reputation: 1

c# wcf service how to consume call java client

../Iservice1.cs/

public interface IService1
    {
        [OperationContract]
        Int32 Add(Int32 Num1, Int32 Num2);
}

../Iservice1.svc.cs/

public class Service1 : IService1
    {
        public Int32 Add(Int32 Num1, Int32 Num2)
        {
            return Num1 + Num2;
        }
}

I created the service. I opened a project in Javada and added the service. But how can I call the service in java "add" method.?
SOLVE:

public class JavaApplication {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        MathService service = new MathService();
        IMathService serv;
        serv = service.getBasicHttpBindingIMathService();
        int x=8, y=2;
        int ans;
        ans=serv.add(x, y);
        System.out.println(ans);
        // TODO code application logic here
    }

}

Upvotes: 0

Views: 1073

Answers (1)

Abraham Qian
Abraham Qian

Reputation: 7522

Take the IntelliJ IDEA as an example.
In Java, there is a webservice client library. It could help us generate the client java code, then we use the client to call the service.
enter image description here
It prompts us to input the WSDL page when the project is opened, WCF usually publish the complete WSDL file by SingleWSDL instead of WSDL page. The SingleWSDL contains all service definitions in one file. Here we input SingleWSDL URL.
enter image description here
We could also take advantage of Tools Menu to add the Webservice client java code.
enter image description here
The ServiceLocator class includes our client java code. We can use automatically generated HelloWolrdClient.java to simulate the invocation, Press Alt+enter to import the jar package.
enter image description here
At last, please do not forget to modify the service URL, the default is localhost.
enter image description here
Run the Main method in HelloWorldClient. Result.
enter image description here
Feel free to let me know if there is anything I can help with.

Upvotes: 1

Related Questions