The communication and introduction of JavaScript and WebService (1/3)

Source: Internet
Author: User

WebService it is a universal model for building applications that can be run in any operating system that supports network traffic; it's a new web WebService
The application branch is a self-contained, self-describing, modular application that can be published, positioned, and invoked via the Web. A Web service is an application component that logically provides data and services to other applications. Each application accesses the Web service through a network protocol and some standard data formats (HTTP,XML,SOAP), via the web The internal execution of the service gets the desired results. Web service can perform any function from simple requests to complex business processes. Once deployed, other Web service applications can discover and invoke the services that it deploys.

using System;
Using System.IO;
Using System.Collections;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Web;
Using System.Web.Services;
Using System.web.services.protocols;
Using System.Drawing;
Using System.Drawing.Imaging;
Namespace Nightkidsservices
{
<summary>
Summary description of Service1
</summary>
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
[ToolboxItem (False)]
public class Testservice:webservice
{
private static int picnum =-1;
[WebMethod]
Public Resource GetResource ()
{
Return Resource.createresource ("Pic2", "ASDFASD", 0);
}
[WebMethod]
public string HelloWorld ()
{
return "Hello";
}
[WebMethod]
Public byte[] Getpic ()
{
Picnum = (picnum + 1)% 32;
Image image = Image.FromFile (This.server.mappath ("jpeg/" + (picnum+1). ToString () + ". bmp"));
MemoryStream mem=new MemoryStream ();
Image.Save (Mem, imageformat.jpeg);
return Mem.getbuffer ();
}
[WebMethod]
Public list<resource> getresourcelist ()
{
return new list<resource> (new resource[] {resource.createresource ("Pic1", "Jpeg/1.bmp", 0), Resource.createresource ("Pic2", "Jepg/2.bmp", 0), Resource.createresource ("Pic3", "Jpeg/3.bmp", 0), Resource.createresource ("Pic4", "Jepg/4.bmp", 0)});
}
}


The above is just a simple test use to facilitate the subsequent use of web effects to deal with different types of data
For JavaScript, it's definitely using the XMLHttpRequest object to access the server side, but for the sake of simplicity, I didn't consider compatibility issues, directly using the XMLHttpRequest object (I used Chrome as a test browser), For this I use the Ajaxclient class for the HTTP operation (POST method), WebService class to encapsulate the processing webservice (invoke the Ajaxclient class as the action Class), Jsonconverter class processes XML data into JSON data
Common.js (including Jsonconverter class)

Home 1 2 3 last

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.