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