Let's create an application that performs SOAP communication in C # and outputs the value obtained from the server to the console.
Let's make a simple application in C # that outputs the value obtained from the web server to the console
GlassFish on application server, application created with Java 1.8 Also, set the data source for DB connection in GlassFish.
I'm using Oracle 12c
SimpleWeb.java
package simple;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayListHandler;
@WebService
public class SimpleWeb {
@WebMethod
public String sayHello(String name) throws Exception{
return _sayHello(name);
}
private String _sayHello(String name)throws Exception{
try{
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/oracle12c");
return ((new QueryRunner())
.query(ds.getConnection(), //Get a connection
"select EMP_ID,EMP_NAME from EMP", //SQL zzzz to execute
new ArrayListHandler())
.stream()
.filter(array->array[0].equals("001"))
.map(array -> String.format("Employee ID:%s:Employee name:%s",array[0],array[1]))
.collect(StringBuilder::new, StringBuilder::append, StringBuilder::append)
.toString());
}catch(Exception e){
e.printStackTrace();
return name;
}
}
}
Specify the URL of the reference destination in "Address" and press the move button.
ConsoleApplication4.cs
using System;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
MyWebService.SimpleWebClient client = new MyWebService.SimpleWebClient();
Console.WriteLine(client.sayHello("test"));
}
}
}
Recommended Posts