Make a SOAP call in C #

At the beginning

Let's create an application that performs SOAP communication in C # and outputs the value obtained from the server to the console.

Outline of the module to be implemented

client

Let's make a simple application in C # that outputs the value obtained from the web server to the console

Web application

GlassFish on application server, application created with Java 1.8 Also, set the data source for DB connection in GlassFish.

DB server

I'm using Oracle 12c

Details of the module to be implemented

Server app implementation

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;
		  }
		  
	  }
}

How to add a client (C #) service reference

    1. Select Service Reference from the Visual Studio Solution Explorer and select Add Service Reference image
  1. Specify the URL of the reference destination in "Address" and press the move button. image

    1. Confirm that the desired Web service is displayed in the "Service" column. If you want to change the service name, change the value of "namespace", image

Client implementation

ConsoleApplication4.cs


using System;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            MyWebService.SimpleWebClient client = new MyWebService.SimpleWebClient();
            Console.WriteLine(client.sayHello("test"));

        }
    }
}

Table referenced by web application

image

Execution result of calling the server application from the client

image

Recommended Posts

Make a SOAP call in C #
Call a C function from Swift
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I made a Ruby extension library in C
How to make a follow function in Rails
ABC --013-A & B & C
ABC --023 --A & B & C
Make Blackjack in Java
Make "I'm not a robot" in Java EE (Jakarta EE)
ABC --010 --A & B & C
ABC --028 --A & B & C
ABC --015 --A & B & C
[CentOS, Eclipse] Load a library file in a C project
ABC --128 --A & B & C
ABC --018 --A & B & C
ABC --054 --A & B & C
Write a class in Kotlin and call it in Java
ABC --017 --A & B & C
ABC --029- A & B & C
ABC --022 --A & B & C
[Personal memo] Make a simple deep copy in Java
ABC --019 --A & B & C
ABC --020 --A & B & C
ABC --030- A & B & C
ABC --127 --A & B & C
I tried to make a login function in Java
ABC --007 --A & B & C
ABC --014- A & B & C
Make a reflection utility ②
Make a reflection utility ③
ABC --016 --A & B & C
ABC --011-A & B & C
ABC --031 --A & B & C
Call a program written in Swift from Processing (Java)
Make a reflection utility ①
ABC --021 --A & B & C
ABC --025 --A & B & C
ABC --024 --A & B & C
ABC --027 --A & B & C
ABC --080- A & B & C
Let's make a calculator application in Java ~ Display the application window
I just wanted to make a Reactive Property in Java
I tried to make a client of RESAS-API in Java
I wrote a C parser (like) using PEG in Ruby
ABC --129- A & B & C & D
Dynamically call methods in JSF
ABC --133- A & B & C & D
Refactoring: Make Blackjack in Java
ABC --122 --A & B & C & D
Multiplication in a Ruby array
Find a subset in Java
Let's make a communication application in LAN Part 4 Set information in JavaFX control / Call JavaFX screen from thread
[Java] Make it a constant
ABC --125- A & B & C & D
ABC --130- A & B & C & D
[Rails] Make a breadcrumb trail
Reproduce Java enum in C #
ABC --126 --A & B & C & D
Make html available in Vapor
Make a rhombus using Java
How to make a jar file with no dependencies in Maven