Communication and introduction between javascript and webservice (1/3)

Source: Internet
Author: User

Webservice is a universal model for building applications. It can be run in any operating system that supports network communication. It is a new web webservice.
Application branches are self-contained, self-described, and modular applications that can be published, located, and called through the web. Web service is an application component that logically provides data and services for other applications. each application accesses the web service through the network protocol and some standard data formats (http, xml, and soap). The results are obtained through the internal execution of the web service. web services can execute any function from simple requests to complex business processing. After deployment, other web service applications can discover and call the services deployed by the application.

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 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. 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 to facilitate subsequent use of webpage special effects to process different types of data
For javascript, the xmlhttprequest object must be used to access the server. However, for simplicity, I did not consider compatibility issues and directly used the xmlhttprequest object (I used chrome as the test browser ), for this reason, I use the ajaxclient class for http operations (post method). The webservice class is used to encapsulate and process webservice (the ajaxclient class is called as the operation class). The jsonconverter class is used to process xml data and convert it to json data.
Common. js (including the jsonconverter class)
1 2 3

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.