62,047
社区成员
发帖
与我相关
我的任务
分享
function SoapWebService()
{
var t = new CreateXmlHttp();
t.URL = "WebService.asmx";
t.OnPostBack = function(){
if (this.readyState == 4) {
alert(this.responseXML.xml);
}
};
//t.Content = "a="+escape("zj")+"&b="+escape("shizhu");
// t.Headers = { "CONTENT-TYPE": "application/x-www-form-urlencoded", "Content-Length": t.Content.length };
t.Content = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <HelloWorld xmlns="http://tempuri.org/"> <a>zj</a> <b>shizhu</b> </HelloWorld> </soap:Body></soap:Envelope>';
t.Headers = { "SOAPAction":"http://tempuri.org/HelloWorld", "Content-Type":"text/xml; charset=utf-8","Content-Length": t.Content.length };
t.Send();
}
function Record()
{
var url = "/WebService.asmx" ;
var uri = "http://www.netufi.cn" ;
var xmlhttp ;
if( window.attachEvent)
{
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
else
{
xmlhttp = new XMLHttpRequest();
}
if(xmlhttp == null)return;
var soapaction = uri + "/" + 'RecordVisited' ;
xmlhttp.open("POST",url,true) ;
xmlhttp.setRequestHeader("SOAPAction", soapaction) ;
xmlhttp.setRequestHeader("Content-Type","text/xml") ;
var content = '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <RecordVisited xmlns="http://www.netufi.cn/"> <url>'+window.location+'</url> <reffer>'+escape(document.referrer)+'</reffer> </RecordVisited> </soap:Body></soap:Envelope> ';
xmlhttp.send (content) ;
using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
/// <summary>
///WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld(string a,string b) {
return string.Format("{0}{1}", a, b);
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script>
function CreateXmlHttp() {
this.XMLHTTP = window.attachEvent ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
this.Method = "POST";
this.URL = "/common/guestbookentity.asp";
this.Content = null;
this.Headers = {};
this.OnPostBack = function() { };
this.Send = function() {
if (this.XMLHTTP == null) {
alert("浏览器不支持动态创建异步请求对像");
return;
};
this.XMLHTTP.onreadystatechange = function(o) { return function() { if (o.OnPostBack) o.OnPostBack.apply(o.XMLHTTP, [o]); }; } (this);
this.XMLHTTP.open(this.Method, this.URL, true);
if (this.Headers) {
for (var property in this.Headers) {
this.XMLHTTP.setRequestHeader(property, this.Headers[property]);
}
}
this.XMLHTTP.send(this.Content);
};
};
function PostWebService()
{
var t = new CreateXmlHttp();
t.URL = "WebService.asmx/HelloWorld";
t.OnPostBack = function(){
if (this.readyState == 4) {
alert(this.responseText);
}
};
t.Content = "a="+escape("zj")+"&b="+escape("shizhu");
t.Headers = { "CONTENT-TYPE": "application/x-www-form-urlencoded", "Content-Length": t.Content.length };
t.Send();
}
</script>
</head>
<body onload="PostWebService()">
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
[WebService(Namespace = "http://tempuri.org/")]
[WebMethod]
public string HelloWorld() {
return "Hello World";
}