Basic Supplements------webservice Detailed

Source: Internet
Author: User
Tags wsdl

Basic supplements

Basic Supplements------webservice Detailed

Basic Supplements------redis Detailed

Basic Supplements------reflection

Basic supplements------commissioned Detailed

Basic Supplements------interface Detailed

Basic Supplements------generic Explanation

Objective

The service interfaces commonly used in the work are three Wcf,webservice and Webapi. first of all, the first contact is webservice, today a general summary.

1.webservice concept-related 1.1.Web Service is also called XML Web service WebService

is a lightweight, independent communication technology that can receive requests passed from other systems on the Internet or intranet. Is: software services provided through SOAP on the web, described using WSDL files, and registered through UDDI.

1.2.XML: (extensible Markup Language) Extensible Markup Language.

Temporary data processing for short-term, web-oriented network, is the basis of soap. It is designed to describe data (XML) rather than display data (HTML). A separate blog is described in detail later.

1.3.Soap: (simple Object Access Protocol).

is the communication protocol for XML WEB Service. Its guiding philosophy is "the only technology that has not invented any new technology." When a user finds your WSDL description document through uddi, He can invoke one or more of the actions in the Web service that you set up by soap. SOAP is a specification for calling methods in the form of XML documents that can support different underlying interfaces, such as HTTP (S) or SMTP.

<?XML version= "1.0"?><Soap:envelopeXmlns:soap= "http://www.w3.org/2001/12/soap-envelope"Soap:encodingstyle= "http://www.w3.org/2001/12/soap-encoding"> <Soap:header>  <M:transxmlns:m= "http://www.w3schools.com/transaction/"Soap:mustunderstand= "1">234</M:trans></Soap:header>  <Soap:body>  <M:getpricexmlns:m= "http://www.w3schools.com/prices">    <M:item>Apples</M:item>  </M:getprice></Soap:body></Soap:envelope>

1.4.WSDL: (web Services Description Language) Web Service Description Language

A WSDL file is an XML document that describes a set of SOAP messages and how to exchange those Messages. In most cases, it is automatically generated and used by the Software.

    • Types -a container for a data type definition that uses a type system (generally using the type system in XML schemas).
    • message -abstract typed definition of the data structure of the communication message. Use the type defined by types to define the data structure of the entire message.
    • Operation -an Abstract Description of the operations supported in the service, typically a single operation describes a request/response message pair for an access portal.
    • PortType -an Abstract collection of operations supported by an access entry point type that can be supported by one or more service access Points.
    • binding-the specific protocol and data format specification bindings for a specific port type.
    • Port -defines A single service access point for which the Protocol/data format binding is combined with a specific Web Access address.
    • A collection of service-related access Points.
    • WSDL describes the three basic properties of a Web service:

      (1) operation provided by the service

      (2) How to access the service

      (3) where the service is located (ok by URL)

1.5.UDDI (Universal Description, Discovery, and Integration)

is a new project focused primarily on Web service providers and Users. Before a user can invoke a Web service, it is important to determine which business methods are included in the service, to find the called interface definition, and to prepare the software on the server side, and UDDI is a mechanism to guide the system through the description document to find the appropriate service. UDDI uses the SOAP message mechanism (standard Xml/http) to publish, edit, browse, and find registration Information. It uses XML format to encapsulate various types of data and send it to the registry or to the registry to return the required Data.

2.. Net WebService

The above theoretical knowledge even if you do not know, want to use WebService or not any difficulty, do not believe you look down.

2.1. creating a WebService (vs2013) 2.1.1. create a new WebService project (new project->c#->web service application, File-so)

After this project, we will see a file called servicedome.asmx, first common webfrom like it is similar to aspx, we directly open the CS code file, asmx file so far has not considered what the use of Him. if you haven't done anything yet, You will see a commented-out HelloWorld webmethod, remove the annotations, and in the run, you will get the simplest webservice running Instance. Click "helloworld" to execute its method. obviously, What this function means to us is only a macro understanding of the way the Web service is Written.

2.1.2.WebMethodAttribute Detailed

[WebMethod (description="note information ")]       public string HelloWorld ()     {      return"HelloWorld";     

As above,WebMethodAttribute This attribute indicates that the method can be called from a remote Web client.

Where WebMethod consists of the following 6 properties

  (1) Description:

Is the information described by the WebService Method. Just like the function comment of the WebService method, you can let the caller see the Comment.

 (2). Enablesession:

Instructs WebService to start the session flag, which is done primarily through cookies, by default False.

 public Static int i=0; [ WebMethod (enablesession=true)]publicint  Count () {i=i+ 1 ; return

As above count () back and save the session similar to keep the information down.

 (3) Messagename:

The main implementation method overloads after Renaming.

 [webmethod]  public  int  Add (int  i, int   J) { return  i + j;} [WebMethod (messagename  = " add2  Span style= "color: #800000;" > " )]  public  int  Add (int  i, int  j, int   k) { return  i + j + k;}} 

 (4). Transactionoption:

Indicates transactional support for XML Web services METHODS.

  (5). Cacheduration:

The Web supports output caching so that WebService does not need to perform multiple passes to improve access efficiency, while CacheDuration is the attribute that specifies the cache Time.

 public Static int i=0; [ WebMethod (enablesession=true, cacheduration=)]publicint Count () {i=i+1; return i;}

  (6). Bufferresponse:

   Configures whether the WebService method waits until the response is fully buffered before sending the message to the requesting Side. Normal application to wait for the complete buffer is not sent! It is only necessary to set BufferResponse to False if the XML Web services method is known to return large amounts of data to the Client. For small amounts of data, setting BufferResponse to True can improve the performance of XML Web Services. When BufferResponse is false, the SOAP extension is disabled for the XML Web services Method.

2.2. Implement WebService

The feature is said to say that our Webserviece service interface implementation, in fact, for his implementation and we implement a class is not much Different. 、

        [WebMethod]        public string syncardtodreams (int start, int end)        {            try            {                DateTime begin = datetime.now;                Usersignservice userservice = new Usersignservice ();                BOOL ret = userservice.synchrocardtodreams (start, end);                DateTime endTime = datetime.now;                Double total = (endtime-begin). totalminutes;                String retmsg = ret? "synchronization succeeded": "synchronization failed";                Return "time of this synchronization" + total + "minutes;" + retmsg;            }            Catch (Exception Ex)            {                return "sync failed:" + Ex. ToString ();            }        }
2.3. Call WebService

Right-click Add Service reference at the project where you want to use the service

This method can then be instantiated directly in the Program:

Call method    Testservicereference.testservicesoapclient Testservice = new Testservicereference.testservicesoapclient ();    int result = Testservice.add (1, 2);

Front-End invocation

<type= "text/javascript">    $ (function () {        $.ajax ({            type: ' POST ',            url: ' testservice.asmx/add ',            data: ' {a:4,b:4} ',            dataType: ' json ',            ContentType: "application/json",            success:function (data) {                alert (data.d);            }        );    }); </ Script >
3. Modify the WebService service Address:

3.1 Modifying a configuration file

<?XML version= "1.0" encoding= "utf-8"?>  <Configuration>      <configsections>      </configsections>      <System.ServiceModel>          <Bindings>              <BasicHttpBinding>                  <bindingname= "pointstoreservicesoap" />              </BasicHttpBinding>          </Bindings>          <Client>              <EndpointAddress= "http://localhost:25548/WebServiceDom.asmx"binding= "basichttpbinding"bindingconfiguration= "pointstoreservicesoap"Contract= "pointstoreservice.pointstoreservicesoap"name= "pointstoreservicesoap" />          </Client>      </System.ServiceModel>  </Configuration> 

Basic Supplements------webservice Detailed

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.