Java soapheader Web Service

Source: Internet
Author: User

C # web servicehttp: // www.jb51.net/article/16768.htm returned in JSON format
Here I use axis to create a class package. First download the axis compressed package, decompress it, and put axis under webapp. If it can be run, it will be OK.
C # Can I directly add the WSDL of the created WebService? Access the WSDL and use axis to generate a class: Java-classpath ".; commons-logging.jar; axis. jar; commons-discovery.jar; jaxrpc. jar; wsdl4j. jar; SAAJ. jar; jaxrpc. jar; mail. jar "org. apache. axis. WSDL. wsdl2java-o "E: \ cjjer" http: // S: 9999/iusers. asmx? WSDL

A series of java files are generated under directory e: \ cjjer.

Then compile these java files. Note that, because there is no soapheader request, you need to modify the Java file yourself:

Open the * soapstub. Java file and find

Protected org. Apache. axis. Client. Call createcall () throws java. RMI. RemoteException

This method, and write it before return.

Soapheaderelement head = new soapheaderelement (New prefixedqname (New javax. xml. namespace. QNAME ("http://www.cjjer.com/webs/", "reqheader ")));
Head. setactor (null );
Try {
Head. addchildelement ("username"). addtextnode ("cjjer ");
Head. addchildelement ("password"). addtextnode ("000000 ");
Head. setmustunderstand (true );
} Catch (exception e ){
System. Out. println ("soapheader exception = ");
E. printstacktrace ();
}
_ Call. addheader (head );

Return _ call;

In this way, the soapheader will be added. If the prompt class cannot be found, import org. Apache. axis. Message .*;

Finally, write the requestCodeNow: Import java. Io .*;
Import java. SQL .*;
Import java. AWT .*;
Import javax. xml. namespace .*;
Import java. AWT. event .*;
Import java.net. url;
Import org. Apache. axis. Client .*;
Import com. cjjer. www. webs .*;

Public class testnet {
// Main method
Public static void main (string ARGs []) {
System. Out. println ("I'm coming in, grack ");
Try {
String endpoint = "http: // S: 9999/iusers. asmx ";
Cjjerlocator locator = new cjjerlocator ();//
Locator. setmaintainsession (true );
Cjjersoap service = locator. getcjjersoap (); // get the service object
Member objm = service. getuser (1 );
System. Out. println (objm. getname ());
}
Catch (exception e ){
E. printstacktrace ();

}

}
}

If no exception occurs, it is OK. If an exception occurs, handle it by yourself.
Compile: javac-CP "E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ commons-logging.jar; E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ axis. jar; E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ commons-discovery.jar; E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ jaxrpc. jar; E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ wsdl4j. jar; E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ SAAJ. jar; E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ jaxrpc. jar; E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ mail. jar; "com/cjjer/www/webs /*. java-xlint: unchecked

Run the test:

Java-CP "E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ commons-logging.jar; E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ axis. jar; E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ commons-discovery.jar; E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ jaxrpc. jar; E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ wsdl4j. jar; E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ SAAJ. jar; E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ jaxrpc. jar; E: \ tomcat6 \ webapps \ axis \ WEB-INF \ Lib \ mail. jar; "testnet
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.