SOAP used in java -----First Example

转载 2006年05月19日 12:08:00

First  we need  :

JAVA 2 SDK 1.4.1,Apache SOAP 2.3.1,JAF 1.0.2,JAVAMAIL 1.3.1, Xerces 2.6.0 , Tomcat 5.0Java SDK,JAF和JAVAMAIL(http://java.sun.com),the other you can down them from(http://jakarta.apache.org)

Second we need set some classpath, listed as follows:

set CATALINA_HOME=C:/Tomcat 5.0
set CLASSPATH=%JAVA_HOME%/lib/tools.jar
set CLASSPATH=%JAVA_HOME%/[your own class drectory ]/soap.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%/  [your own class drectory ]/mail.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%/[your own class drectory ]/activation.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%/[your own class drectory ]/xercesImpl.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%/[your own class drectory ]/xercesSamples.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%/[your own class drectory ]/xml-apis.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%/[your own class drectory ]/xmlParserAPIs.jar
set CLASSPATH=%CLASSPATH%;%CATALINA_HOME%/common/lib/servlet.jar
set CLASSPATH=%CLASSPATH%;%CATALINA_HOME%/common/lib/tools.jar

Third Class we use here

package com.test.SOAPTest;

public class SOAPService {
 public String sayHi(String x) {
  return ("Hello my friend, " + x + "! Glad to see you!");
 }
}

then open tomcat ,type the address http://localhost:8080/soap/   , run "Run the admin client ", and input:

ID: urn:HelloWorld_SOAPService
Scope: Application
Methods: sayHi
Provider Type: java
Java Provider - Provider Class: HelloWorld.SOAPService
Java Provider - Static? No

ok,then you can copy the class SOAPService to [Tomcat_home]/common/classes ,

now ,we create the SOAPClient  here,you can see the detail

package com.test.SOAPTest;

import java.net.*;
import java.util.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;

public class HelloWorldClient {
 public static void main(String[] arg) throws Exception {
  Call c = null;
  URL url = null;
  Vector params = null;
  Response rep = null;
  String ourName = "Superman";
  String ourUrn = "urn:HelloWorld_SOAPService";
  String ourMethod = "sayHi";
  url = new URL("http://localhost:8080/soap/servlet/rpcrouter");
  System.out.println("Passing to our deployed " + ourUrn + "our name ("
    + ourName + "): ");
  c = new Call();
  c.setTargetObjectURI(ourUrn);
  c.setMethodName(ourMethod);
  c.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
  params = new Vector();
  params
    .addElement(new Parameter("ourName", String.class, ourName,
      null));
  c.setParams(params);
  System.out.print("and its answer is: ");
  rep = c.invoke(url, "");
  if (rep.generatedFault()) {
   Fault fault = rep.getFault();
   System.out.println("/nCall failed!");
   System.out.println("Code = " + fault.getFaultCode());
   System.out.println("String = " + fault.getFaultString());
  } else {
   Parameter result = rep.getReturnValue();
   System.out.print(result.getValue());
   System.out.println();
  }
 }
}

Till now we have finished all the work ,then we can run it.

Run tomcat and test our client ,we will see the result " hello my friend,superman,Glad to see you!"

Over!

Java SOAP API example

http://stackoverflow.com/questions/15948927/working-soap-client-example import javax.xml.soap.*; ...
  • u010157717
  • u010157717
  • 2016-10-28 01:56:29
  • 306

深入理解Java String类

一、String类想要了解一个类,最好的办法就是看这个类的实现源代码,来看一下String类的源码:public final class String implements java.io.S...
  • xhyxxx
  • xhyxxx
  • 2017-03-24 11:39:54
  • 351

读thinking in java的收获(二) --eclipse生成javadoc文档

最开始学习java语言的时候学过生成javadoc不过当时只是用windows命令行生成。读了这里的javadoc温故而知新发现其实我们做的项目就用到了一些注释,只是没有用eclipse 生成这份文...
  • u012453607
  • u012453607
  • 2015-01-30 21:26:45
  • 657

autotools-practice

http://www.aireadfun.com/blog/2012/12/03/study-automake/ [fpxshyy@localhost makefpxshyykit]$ tar zx...
  • liufengl138
  • liufengl138
  • 2015-07-15 16:24:49
  • 809

Code First :使用Entity. Framework编程(7)

第7章 高级概念 The Code First modeling functionality that you have seen so far should be enough to g...
  • educast
  • educast
  • 2012-05-22 09:53:27
  • 6190

gradle编译无法初始化jvm问题

用gradle编译ionic程序时,报以下错误:Error:Unable to start the daemon process. This problem might be caused by in...
  • xujinfu2
  • xujinfu2
  • 2016-01-12 16:50:54
  • 4766

A SOAP Example in Java

A SOAP Example in Java You can use SOAP with Java by using Web services, but doing so is more advan...
  • ku1989
  • ku1989
  • 2012-11-27 23:27:32
  • 886

深入了解String类

一、String类 想要了解一个类,最好的办法就是看这个类的实现源代码,来看一下String类的源码: public final class String implements...
  • Java_interface
  • Java_interface
  • 2017-08-24 08:37:09
  • 4129

String, StringBuilder , StringBuffer

1.        string类的源码: public final class String implements java.io.Serializable, Comparable, Ch...
  • xiazhimeng
  • xiazhimeng
  • 2015-07-14 20:16:20
  • 101

Shell编程基础总结

Shell编程基础总结 #!/bin/bash #This is my first shell script. echo -n "The current date and time is:" d...
  • renli2549
  • renli2549
  • 2018-01-19 13:09:08
  • 31
收藏助手
不良信息举报
您举报文章:SOAP used in java -----First Example
举报原因:
原因补充:

(最多只允许输入30个字)