Asp.net exercise js calls webservice, asp. netwebservice
[Csharp]View plaincopyprint?
- Using System;
- Using System. Collections. Generic;
- Using System. Linq;
- Using System. Web;
- Using System. Web. Services;
- /// <Summary>
- /// Summary of JsWebServiceTest
- /// </Summary>
- [WebService (Namespace = "http://tempuri.org/")]
- [WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
- // To allow ASP. net ajax to call this Web service from a script, cancel the comments to the downstream.
- [System. Web. Script. Services. ScriptService]
- Public class JsWebServiceTest: System. Web. Services. WebService {
- Public JsWebServiceTest (){
- // If you use the designed component, uncomment the following line
- // InitializeComponent ();
- }
- [WebMethod]
- Public string HelloWorld (){
- Return "Hello World ";
- }
- [WebMethod]
- Public string WelCome (string name)
- {
- Return name + ": Welcome ";
- }
- }
Note: To call the webservice method in js, uncomment system. web. script. services. scriptservice.
[Html]View plaincopyprint?
- <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "WebServiceForm2.aspx. cs" Inherits = "test2_WebServiceForm2" %>
- <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <Html xmlns = "http://www.w3.org/1999/xhtml">
- <Head runat = "server">
- <Title> </title>
- </Head>
- <Body>
- <Form id = "form1" runat = "server">
- <Div>
- <Asp: ScriptManager ID = "ScriptManager1" runat = "server">
- <! -- Reference web Services -->
- <Services>
- <Asp: ServiceReference Path = "~ /WebService/JsWebServiceTest. asmx "/>
- </Services>
- </Asp: ScriptManager>
- <Input type = "button" value = "View" onclick = "jsCallWeb ();"/>
- <Br/>
- <Input type = "button" value = "View 2" onclick = "jsCallWeb2 ();"/>
- </Div>
- </Form>
- </Body>
- </Html>
- <Script type = "text/javascript">
- // Call 1
- Function jsCallWeb (){
- JsWebServiceTest. HelloWorld (outResult );
- }
- // Call 2
- Function jsCallWeb2 (){
- JsWebServiceTest. WelCome ('kevin ', outResult );
- }
- // Output result
- Function outResult (result ){
- Alert (result );
- }
- </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.