javascript與webservice的通訊與介紹(1/3)

來源:互聯網
上載者:User

webservice它是一種構建應用程式的普遍模型,可以在任何支援網路通訊的作業系統中實施運行;它是一種新的web  webservice
應用程式分支,是自包含、自描述、模組 化的應用,發行就緒、定位、通過web調用。web service是一個應用組件,它邏輯性的為其他應用程式提供資料與服務.各應用程式通過網路通訊協定和規定的一些標準資料格式(http,xml,soap)來訪問web service,通過web service內部執行得到所需結果.web service可以執行從簡單的請求到複雜商務處理的任何功能。一旦部署以後,其他web service應用程式可以發現並調用它部署的服務。

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>
/// 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) });
}
}


以上只是一個簡單的測試使用,便於後續使用網頁特效處理不同類型的資料
對於javascript,肯定是使用xmlhttprequest對象來訪問伺服器端的,不過這裡為了簡單,我沒有考慮相容性問題,直接使用xmlhttprequest對象(我使用chrome瀏覽器作為測試瀏覽器),為此我使用ajaxclient類來進行http操作(post 方法),webservice類來封裝處理webservice(調用ajaxclient類作為操作類),jsonconverter類處理xml資料轉換為json資料
common.js(包含jsonconverter類) 

首頁 1 2 3 末頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.