Http://dev2dev.bea.com.cn/bbs/thread.jspa? Forumid = 97301 & threadid = 38818 & tstart = 0 There was no time to post this item. It was found that only the Web Service written in Java was written..ProgramCalled part So nowArticleI hope it will help you. Author: duansiyang 2. Web Services written in C # are called by Java programs ----- First, create a web service in Visual Studio. NET 2003. Of course, if you already have one, you can skip this step ----- (1) file-> New-> Project (the younger brother uses the Chinese version, please forgive me for the English version) (2) Select Visual C # project as the project type, select Asp.net web service on the right, and enter the project location as http: // localhost/aspwebservice. (3) Click OK to create a project. (4) In Solution Explorer on the right, select aspwebservice, right-click, and choose add> Add Web Service option. (5) Enter testservice. asmx. (6)CodeView, enter the following code // Calculate the sum of two values for the Web service with parameters. [Webmethod] [Soaprpcmethod (Action = "http://www.duansiyang.com/Rpc", requestnamespace = "http://www.duansiyang.com/SU", responsenamespace = "http://www.duansiyang.com/SU")] Public long counter (long a, long B) { Return A + B; } // A web service without parameters generates a random number between 0 and 1. [Webmethod] [Soaprpcmethod (Action = "http://www.duansiyang2.com/Rpc", requestnamespace = "http://www.duansiyang2.com/SU", responsenamespace = "http://www.duansiyang2.com/SU")] Public double randomnumber () { Random rad = new random (1 ); Double radnext = rad. nextdouble (); Return radnext; } (7) you also need to reference a namespace Using system. Web. Services. Protocols; (8) Compile this project. ----- Create a called servlet in JBuilder. Of course, jsp can also be used. For example ----- (1) create a new project (everyone should be familiar with it, so I won't talk about it) (2) create a web module (3) create a servlet named testaspwebsvrservlet. (4) Add the following code Try { Long I = new long (1 ); Long J = new long (2 ); String endpoint = "Http: // localhost/aspwebservice/testservice. asmx "; Service = new service (); Call call = (CALL) service. createcall (); Call. settargetendpointaddress (New java.net. URL (endpoint )); Call. setoperationname (New QNAME ("http://www.duansiyang.com/SU", "counter ")); Call. addparameter ("A", org. Apache. axis. encoding. xmltype. xsd_date, Javax. xml. rpc. parametermode. In ); Call. addparameter ("B", org. Apache. axis. encoding. xmltype. xsd_date, Javax. xml. rpc. parametermode. In ); Call. setreturntype (Org. Apache. axis. encoding. xmltype. xsd_long ); Call. setusesoapaction (true ); Call. setsoapactionuri ("http://www.duansiyang.com/Rpc "); Long k = (long) Call. Invoke (new object [] {I, j }); System. Out. println ("result is" + K. tostring () + "."); } Catch (exception e ){ System. Err. println (E. tostring ()); }
Try {
String endpoint = "Http: // localhost/aspwebservice/testservice. asmx "; Service = new service (); Call call = (CALL) service. createcall (); Call. settargetendpointaddress (New java.net. URL (endpoint )); Call. setoperationname (New QNAME ("http://www.duansiyang2.com/SU", "Total ")); Call. setreturntype (Org. Apache. axis. encoding. xmltype. xsd_double ); Call. setusesoapaction (true ); Call. setsoapactionuri ("http://www.duansiyang2.com/Rpc "); Double K = (double) Call. Invoke (new object [0]); System. Out. println ("result is" + K. tostring () + "."); } Catch (exception e ){ System. Err. println (E. tostring ()); } (5) you also need to import the following package Import javax. servlet .*; Import javax. servlet. http .*; Import java. Io .*; Import java. util .*; Import java. util. date; Import java. Text. dateformat; Import javax. xml. namespace. QNAME; Import javax. xml. rpc. parametermode; Import org. Apache. axis. Client. call; Import org. Apache. axis. Client. Service; (6) run and you can see the result. So far, on the end of this article, if you have any opinions, you can send an email to my mailbox duansiyang@tom.com or add my QQ: 365786120 to contact me. Thank you! |