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 the 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 go to 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 Request Code:
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