我爱Aspx >> Asp.Net >> 从Web Services中访问服务器变量从Web Services中访问服务器变量
中最经常被问到的问题就是“如何从一个web Services(Web服务)内部获取客户浏览器的IP地址?” 这个问题的答案非常简单。system.web.services名称空间内部的Context类代表了web服务的上下文。换句话说,它从一个正在运行的web服务内部对不同的对象进行引用。比如Response(响应)、Request(请求)和Session对象,以及在服务上调试是否激活之类的信息。
本文我们用一个非常基本的例子来描述两件事:
1、取得客户浏览器的IP地址
2、取得所有的web 服务器变量
源代码如下,很容易理解:
<%@ Webservice Language="C#" class="httpvars" %>
using System;
using System.Collections;
using System.Web.Services;
public class httpvars : WebService
{
// This method returns the IP address of the client
[WebMethod]
public String ipAddress ()
{
// The Context object contains reference to Request object
return Context.Request.ServerVariables["REMOTE_ADDR"];
}
// This method returns the all the server variables as HTML
Ҷƪл˵?
测试 XML Web 服务和应用程序(自..[05-28]
Consuming a Webservice Part 2 ..[05-28]
Creating a Webservice Part 1 o..[05-28]
一个用webservice behavior实现的..[05-28]
加强 WEB SERVICE 的安全性[05-28]
WebService Behavior的一个中文B..[05-28]
Web服务到底是什么(转)[05-28]
WEB服务有待实践的检验[05-28]
一个webseveice的例子[05-28]
正确认识“Web服务”( 转)[05-28]
测试 XML Web 服务和应用程序(自..[05-28]
Create and Control Windows Ser..[05-28]
Create and Control Windows Ser..[05-28]
Create and Control Windows Ser..[05-28]
Create and Control Windows Ser..[05-28]
Consuming a Webservice Part 2 ..[05-28]
Creating a Webservice Part 1 o..[05-28]
一个用webservice behavior实现的..[05-28]
加强 WEB SERVICE 的安全性[05-28]
WebService Behavior的一个中文B..[05-28]