Asp.net exercise js calls webservice, asp. netwebservice

Source: Internet
Author: User

Asp.net exercise js calls webservice, asp. netwebservice

 

 

[Csharp]View plaincopyprint?
  1. Using System;
  2. Using System. Collections. Generic;
  3. Using System. Linq;
  4. Using System. Web;
  5. Using System. Web. Services;
  6. /// <Summary>
  7. /// Summary of JsWebServiceTest
  8. /// </Summary>
  9. [WebService (Namespace = "http://tempuri.org/")]
  10. [WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
  11. // To allow ASP. net ajax to call this Web service from a script, cancel the comments to the downstream.
  12. [System. Web. Script. Services. ScriptService]
  13. Public class JsWebServiceTest: System. Web. Services. WebService {
  14. Public JsWebServiceTest (){
  15. // If you use the designed component, uncomment the following line
  16. // InitializeComponent ();
  17. }
  18. [WebMethod]
  19. Public string HelloWorld (){
  20. Return "Hello World ";
  21. }
  22. [WebMethod]
  23. Public string WelCome (string name)
  24. {
  25. Return name + ": Welcome ";
  26. }
  27. }

 

Note: To call the webservice method in js, uncomment system. web. script. services. scriptservice.

 

 

[Html]View plaincopyprint?
  1. <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "WebServiceForm2.aspx. cs" Inherits = "test2_WebServiceForm2" %>
  2. <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <Html xmlns = "http://www.w3.org/1999/xhtml">
  4. <Head runat = "server">
  5. <Title> </title>
  6. </Head>
  7. <Body>
  8. <Form id = "form1" runat = "server">
  9. <Div>
  10. <Asp: ScriptManager ID = "ScriptManager1" runat = "server">
  11. <! -- Reference web Services -->
  12. <Services>
  13. <Asp: ServiceReference Path = "~ /WebService/JsWebServiceTest. asmx "/>
  14. </Services>
  15. </Asp: ScriptManager>
  16. <Input type = "button" value = "View" onclick = "jsCallWeb ();"/>
  17. <Br/>
  18. <Input type = "button" value = "View 2" onclick = "jsCallWeb2 ();"/>
  19. </Div>
  20. </Form>
  21. </Body>
  22. </Html>
  23. <Script type = "text/javascript">
  24. // Call 1
  25. Function jsCallWeb (){
  26. JsWebServiceTest. HelloWorld (outResult );
  27. }
  28. // Call 2
  29. Function jsCallWeb2 (){
  30. JsWebServiceTest. WelCome ('kevin ', outResult );
  31. }
  32. // Output result
  33. Function outResult (result ){
  34. Alert (result );
  35. }
  36. </Script>



 


How to call a webservice method in ASPnet

1. Create an asp.net site
2. Add a web reference and enter the url of the webservice, which is assumed to be localhost/Service. asmx.
3. Click Go and then click the method you want to call.
4. Initialization
Xx. Service s = new xx. Service ()
S. Method ().....
5. Call

Why does ASPNET call Webservice?

I have not come up with a better solution for the moment. The current idea is to have a single server. Currently, the server has a dual Nic, And that server also has a dual Nic. The two servers share a network card and create a LAN. Then the intermediate server uses another Nic to dial the VPN. In this way, communication is conducted without environment testing and the effect is unknown.

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.