本文目錄一覽:
怎麼用javascript連接webservice
直接上示例代碼 :
MyService.asmx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml;
/// summary
///MyService 的摘要說明
/// /summary
[WebService(Namespace = “”)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允許使用 ASP.NET AJAX 從腳本中調用此 Web 服務,請取消對下行的注釋。
[System.Web.Script.Services.ScriptService]
public class MyService : System.Web.Services.WebService {
public MyService () {
//如果使用設計的組件,請取消注釋以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return “Hello World”;
}
[WebMethod]
public XmlNode xml() {
XmlDocument doc = new XmlDocument();
doc.LoadXml(“hiHello World/hi”);
return doc.FirstChild;
}
[WebMethod]
public string add(int a, int b)
{
return (a + b)+””;
}
}
aspx頁面
html xmlns=””
head runat=”server”
title/title
script language=”javascript” type=”text/javascript”
// !CDATA[
function Button1_onclick() {
var data;
data = “?xml version=\”1.0\” encoding=\”utf-8\”?”
+”soap12:Envelope xmlns:xsi=\”\” xmlns:xsd=\”\” xmlns:soap12=\”\””
+ “soap12:Body”
+ “HelloWorldResponse xmlns=\”\””
+ “HelloWorldResultstring/HelloWorldResult”
+ “/HelloWorldResponse”
+ “/soap12:Body”
+”/soap12:Envelope”;
var xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”);
var URL = “MyService.asmx”;
xmlhttp.Open(“POST”, URL, false);
xmlhttp.SetRequestHeader(“Content-Type”, “text/xml; charset=gb2312”);
xmlhttp.SetRequestHeader(“SOAPAction”, “”);
xmlhttp.setRequestHeader(“Content-Length”, data.length);
xmlhttp.Send(data);
var xml = xmlhttp.responseText;
var doc = new ActiveXObject(“Microsoft.XMLDOM”);
doc.loadXML(xml);
//alert(doc.selectSingleNode(“//HelloWorldResult”).text);
//alert(doc.xml);
alert(doc.selectSingleNode(“//HelloWorldResponse”).childNodes[0].nodeName);
}
function add() {
var a = 10;
var b = 15;
var data;
data = “?xml version=\”1.0\” encoding=\”utf-8\”?”
+ “soap12:Envelope xmlns:xsi=\”\” xmlns:xsd=\”\” xmlns:soap12=\”\””
+ “soap12:Body”
+ “add xmlns=\”\””
+ “a”+a+”/a”
+ “b”+b+”/b”
+ “/add”
+ “/soap12:Body”
+ “/soap12:Envelope”;
var xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”);
var URL = “MyService.asmx”;
xmlhttp.Open(“POST”, URL, false);
xmlhttp.SetRequestHeader(“Content-Type”, “text/xml; charset=gb2312”);
xmlhttp.SetRequestHeader(“SOAPAction”, “”);
xmlhttp.setRequestHeader(“Content-Length”, data.length);
xmlhttp.Send(data);
var xml = xmlhttp.responseText;alert(xml);
var doc = new ActiveXObject(“Microsoft.XMLDOM”);
doc.loadXML(xml);
}
function getxml() {
var a = 10;
var b = 15;
var data;
data = “?xml version=\”1.0\” encoding=\”utf-8\”?”
+ “soap12:Envelope xmlns:xsi=\”\” xmlns:xsd=\”\” xmlns:soap12=\”\””
+ “soap12:Body”
+ “add xmlns=\”\””
+ “/soap12:Body”
+ “/soap12:Envelope”;
var xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”);
var URL = “MyService.asmx”;
xmlhttp.Open(“POST”, URL, false);
xmlhttp.SetRequestHeader(“Content-Type”, “text/xml; charset=gb2312”);
xmlhttp.SetRequestHeader(“SOAPAction”, “”);
xmlhttp.setRequestHeader(“Content-Length”, data.length);
xmlhttp.Send(data);
var xml = xmlhttp.responseText; alert(xml);
var doc = new ActiveXObject(“Microsoft.XMLDOM”);
doc.loadXML(xml);
}
// ]]
/script
/head
body
form id=”form1″ runat=”server”
div
input id=”Button1″ type=”button” value=”button” onclick=”getxml()” /
/div
/form
/body
/html
LINQ的原理淺析
LINQ(Language Integrated Query)是Visual Studio 2008中的領軍人物。藉助於LINQ技術,我們可以使用一種類似SQL的語法來查詢任何形式的數據。目前為止LINQ所支持的數據源有SQL Server、Oracle、XML(標準通用標記語言下的一個應用)以及內存中的數據集合。開發人員也可以使用其提供的擴展框架添加更多的數據源,例如MySQL、Amazon甚至是GoogleDesktop。
一般來講,這類查詢語句的一個重要特點就是可以並行化執行。雖然有些情況下並行可能會帶來一些問題,但這種情況非常少見。這樣也就水到渠成地引出了PLINQ這個並行處理的LINQ類庫。
PLINQ原名為Parallel LINQ,支持XML和內存中的數據集合。執行於遠程伺服器上的查詢語句(例如LINQ to SQL)顯然無法實現這個功能。
將LINQ語句轉換為PLINQ語句極為簡單——只需要在查詢語句中From子句所指定的數據源的最後添加.AsParallel()即可。隨後Where、OrderBy和Select子句將自動改為調用這個並行的LINQ版本。
據MSDN Magazine介紹,PLINQ可以以三種方式執行。第一種是管道處理:一個線程用來讀取數據源,而其他的線程則用來處理查詢語句,二者同步進行——雖然這個單一的消費線程可能並不那麼容易與多個生產線程同步。不過若是能夠仔細配置好負載平衡的話,仍然會極大地減少內存佔用。
第二種模式叫做「stop and go」,用於處理結果集需要被一次返回時(例如調用ToList、ToArray或對結果排序)的情況。在這種模式下,將依次完成各個處理過程,並將結果統一返回給消費線程。這個模式在性能上將優於第一種模式,因為它省去了用來保持線程同步所花費的開銷。
最後一種方法叫做「inverted enumeration」。該方法並不需要實現收集到所有的輸出,然後在單一的線程中處理,而是將最終調用的函數通過ForAll擴展傳遞到每個線程中。這是目前為止最快的一種處理模式,不過這需要傳遞到ForAll中的函數是線程安全的,且最好不包含任何lock之類的互斥語句。
若是PLINQ中任意的一個線程拋出異常,那麼所有的其他線程將會被終止。若是拋出了多個異常,那麼這些異常將被組合成一個MultipleFailuresException類型的異常,但每個異常的調用堆棧仍會被保留。
linq查詢語句
where lbbn.length = 2
就行了
var table = cache_cplb.where( o= o.lbbh.length = 2).toList();
foreach(row in table)
{
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/198678.html