[WebService (Description ="temperature service", Namespace ="http://aaa/webapplication1/webservices")][WebMethod]
public double tocelsius(double tf)
{
return (5d/9d)*(tf-32);
}[WebMethod]
public double tofahrenheit(double tc)
{
return (9d/5d)*(tc+32);
}
这是我写的一个xml web服务我现在想问
怎么在写一个页面(a.htm)去调用这个xml web服务(用soap,http-post我知道)
public double tocelsius(double tf)
{
return (5d/9d)*(tf-32);
}[WebMethod]
public double tofahrenheit(double tc)
{
return (9d/5d)*(tc+32);
}
这是我写的一个xml web服务我现在想问
怎么在写一个页面(a.htm)去调用这个xml web服务(用soap,http-post我知道)
解决方案 »
- 在.net中DropDownList控件是不是不能试用样式啊?
- asp.net 页面加载中效果,怎么实现?
- 散分(1')个人站点相互做友情链接
- 用户密码加解密
- ASP.NET 数据访问类1
- 邮件附件问题!!!!!!!!!!!!!!!急
- Exception of type System.Exception was thrown. 这个错误是什么错误?
- 关于表格的tbl.control.*()用多少,谁能帮我统计一下。
- 我想买台电脑,现在时机怎样,用等910芯片组吗?大家给我个7000以内的配置,要液晶显示器,感谢
- 在IIS中打开ASPnet2.0 出错?
- .net编译之后跳出这个提示“试图运行项目时出错:无法在web服务器上启动调试。未将项目配置设为调试”
- .NET的奇怪问题,数据库连接与Session变量
var myService = "http://192.168.7.108/WebService/NewsService.asmx" ;
var myMethod = "http://tempuri.org/HasNewMessage";
var requestHttp = new ActiveXObject("Microsoft.XMLHTTP");
var requestBody = "";
requestBody = requestBody + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" ; requestBody = requestBody + "<soap:Envelope ";
requestBody = requestBody + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
requestBody = requestBody + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " ;
requestBody = requestBody + "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" ; requestBody = requestBody + " <soap:Body>\n" ;
requestBody = requestBody + " <HasNewMessage xmlns=\"http://tempuri.org/\">\n" ;
requestBody = requestBody + " <userID>" + userID + "</userID>\n";
requestBody = requestBody + " </HasNewMessage>\n";
requestBody = requestBody + " </soap:Body>\n";
requestBody = requestBody + "</soap:Envelope>";
requestHttp.Open("POST",myService,false);
requestHttp.SetRequestHeader("Content-Type","text/xml;charset=gb2312");
requestHttp.SetRequestHeader("SOAPAction",myMethod);
requestHttp.Send(requestBody);// 发送请求
var result = requestHttp.ResponseXML; //返回请求,结果保存在XML中,要拆解出来
var pos1 = result .xml.indexOf("<HasNewMessageResult>"); var pos2 = result .xml.indexOf("</HasNewMessageResult>");
var len = pos2 - pos1 - ("<HasNewMessageResult>").length; var userName = result.xml.substr(pos1 + ("<HasNewMessageResult>").length , len);
pos1 = result.xml.indexOf("<mailCount>"); pos2 = result.xml.indexOf("</mailCount>");
len = pos2 - pos1 - ("<mailCount>").length; var mailCount = result.xml.substr(pos1 + ("<mailCount>").length , len); pos1 = result.xml.indexOf("<pendingCount>"); pos2 = result.xml.indexOf("</pendingCount>"); len = pos2 - pos1 - ("<pendingCount>").length; var pendingCount= result.xml.substr(pos1 + ("<pendingCount>").length , len);
是用一个htm表单来实现的
soap要这么复杂啊?
var xmlDOC = new ActiveXObject("MSXML.DOMDocument");var strWebserviceURL = "http://localhost/testss/Service1.asmx/tocelsius";var strRequest = "tf=111";
objHTTP.Open( "POST", strWebserviceURL, false);
objHTTP.SetRequestHeader( "Content-Type", "application/x-www-form-urlencoded");
objHTTP.Send(strRequest);var bOK = xmlDOC.load(objHTTP.responseXML);if(objHTTP.Status==200)
{
xmlDOC.save("c:\\aaa.xml");
}不过,象这样的方法,在ASP,VB中也一样是可用的。