An example of a web service

zhaozj2021-02-16  52

Web service example (written by yourself, it seems to be a propaganda to yourself, but there is no other example to say that you will say that you will be): http://www26.brinkster.com/ipservices/ip.asmx, this Services is dry Things, you give it IP, it returns the location of IP (Beijing, Shanghai) or empty (it doesn't know). The returned structure is this: public class ipinfo {public string ip; public string address = ""

There is only one function available: [WebMethod] public ipinfo getipinfo (String IP) {// ...}

If you use it in the .NET environment, you must first claim to claim its agent DLL (I don't know how to turn in China is a client wrapper), and other environments are also very different. The package program is automatically generated in .NET (unfortunately do not know how to map), the following is the code of the automatically generated parcel (I use web matrix):

/ / -------------------------------------------------------------------------------------------- ------------------------------ //

// this code was generated by a Tool.

// Runtime Version: 1.1.4322.573

//

// Changes to this file may Cause IncorRect Behavior and Will Be Lost IF

// The code is regenerated.

//

/ / -------------------------------------------------------------------------------------------- ------------------------------

//////ASP.NET Web Matrix // USING System.diagnostics; use system.xml.serialization; use system.Web.Services.protocols; use system.net.com;

///

[System.diagnostics.debuggerstepthroughattribute ()]

[System.componentmodel.designercategoryAttribute ("code")]]]]]

[System.web.services.WebserviceBindingAttribute (name = "ipsoap", namespace = "

Http://www26.brinkster.com/ipservices/ip.asmx")]public class ip: system.web.services.protocols.soaphttpClientProtocol {//////

Public IP () {

this.url = "

Http://www26.brinkster.com/ipservices/ip.asmx ";} ///

[System.web.Services.protocols.soapdocumentMethodattribute ("

Http://www26.brinkster.com/ipservices/ip.asmx/getipinfo ", RequestNamespace =" http://www26.brinkster.com/ipservices/ip.asmx ", responseenamespace =" http: //www26.brinkster. com / ipservices / ip.asmx ", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] public IPInfo GetIPInfo (string ip) {object [] results = this.invoke ("getipinfo", new object [ip}); return ((ipinfo));} /// public system.iasyncResult BegingeTipinfo (String IP, System.asyncCallback Callback, Object askYNCSTATE) {

Return this.beginInvoke ("getipinfo", new object [] {

IP}, Callback, AsyncState;

}

///

Public ipinfo endgetipinfo (system.iasyncResult asyncRESULT) {

Object [] results = this.endinvoke (asyncResult);

Return ((ipinfo) (Results [0]));

}

}

///

[System.xml.serialization.xmltypeattribute (Namespace = "

Http://www26.brinkster.com/ipservices/ip.asmx")]public class ipinfo {////

Public String IP;

///

Public String Address;

}

Compile it, generate an ip.dll, use it like this, in your code.

IP ip = new ip (); this.address.text = IP.Getipinfo ("192.168.100.1"). Address;

The IP is that agent class address is used to display the address of Label, 192.168.100.1 to check.

The location of the customer can be displayed in Label. It should be very simple, and there is no difference between the general class function.

Two points: 1. The agent class is necessary. He simplifies a lot of clients, and even does not need to know that the call is web services, or the general class function, their syntax is the same. 2, the proxy class automatically generates the type of returned (of course, there is restricted), which is more simplified.

转载请注明原文地址:https://www.9cbs.com/read-18471.html

New Post(0)