監(jiān)理公司管理系統(tǒng) | 工程企業(yè)管理系統(tǒng) | OA系統(tǒng) | ERP系統(tǒng) | 造價(jià)咨詢管理系統(tǒng) | 工程設(shè)計(jì)管理系統(tǒng) | 甲方項(xiàng)目管理系統(tǒng) | 簽約案例 | 客戶案例 | 在線試用
X 關(guān)閉

Accessing Server Variables From Within Web Services

申請(qǐng)免費(fèi)試用、咨詢電話:400-8352-114

AMTeam.org

Accessing Server Variables From Within Web Services

 

Manohar Kamath

April 2, 2001

Level: Beginner

One of the most often asked question in newsgroups is "How do I get the IP address of the client browser within a web service?" The answer is very simple. The Context class within the system.web.services namespace represents the context of the web service. In other words, it has reference to various objects from within a running web service -- things like Response, Request and Session objects, and also such information as if the debugging is enabled on the service.

In this article, we will take a look at a very basic example that describes two things

Retrieve the IP address of the client browser

Retrieve all the web server variables

The source code is self explanatory, and is not supposed to be an introduction to web services (for such articles, refer to Web Services. Part I: The Basics).

<%@ 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
   
[WebMethod]
   
public String allHttpVars ()
   
{
       
// Instantiate a collection that will hold the
       
// key-value collection of server variables
       
NameValueCollection serverVars;
       
String returnValue = "";

serverVars = Context.Request.ServerVariables;

 // Retrieve all the Keys from server variables collection
      
  // as a string array
       
String[] arVars = serverVars.AllKeys;

 // Loop through the keys array and obtain the
       
// values corresponding to the individual keys
       
for (int x = 0; x < arVars.Length; x++)
       
{
           
returnValue+= "<b>" + arVars[x] + "</b>: ";
           
returnValue+= serverVars[arVars[x]] + "<br>";
       
}
       
return returnValue;
   
}

}

Demo Code

The second method allHttpVars() returns HTML.

發(fā)布:2007-03-25 13:24    編輯:泛普軟件 · xiaona    [打印此頁]    [關(guān)閉]
相關(guān)文章:
石家莊OA系統(tǒng)
聯(lián)系方式

成都公司:成都市成華區(qū)建設(shè)南路160號(hào)1層9號(hào)

重慶公司:重慶市江北區(qū)紅旗河溝華創(chuàng)商務(wù)大廈18樓

咨詢:400-8352-114

加微信,免費(fèi)獲取試用系統(tǒng)

QQ在線咨詢