Web Service creation and calling between Java and Asp.net (2)

Source: Internet
Author: User

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!

Personal opinion! If any, please forgive me !!!

If you have any comments, you can contact me via my mailbox: duansiyang@tom.com, you can also add my QQ: 365786120

Whx1977[Moderator]

Number of senders: 6,941
Active points: 5,630
Technical Points: 78
Available value: 3,000
Registration Date: 2004-2-29
User status: normal

Re: [original] Web Service creation and calling between Java and Asp.net (2)

Submission time: Jan 28,200 7 4:37:15

Reference Reply Send message
Easy to understand!
Wu haoxian rainbow
Friend, I love you!
Http://dev2dev.bea.com.cn/blog/whx1977/

Have a problem first look: http://edocs.bea.com/
Download BEA WebLogic Server
Http://dev2dev.bea.com.cn/bbs/thread.jspa? Forumid = 81 & threadid = 28193 & tstart = 0
Bea AquaLogic user interaction & BPM & pep
Http://dev2dev.bea.com.cn/bbs/thread.jspa? Forumid = 142667 & threadid = 45540 & messageid = 270183 #270183

I love life! I love Bea!
Because here's my lovely friends!
Don't look around, it's you!

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.