今天利用vs.net2005(C#) 开发了一个WebService用来和Flex做数据交互,

地址:http://localhost/webserv/getData.asmx

这个地址在本地可以正常使用,但是在远程电脑上不能使用,提示“只能本地测试”,没有调用按钮,

在网上搜索一下找到了一个可行的解决方法,具体如下

如果想在远程可以正常调用,需要修改web.config,在system.web节下面加上下面一段话即可

<webServices >
      <protocols >
        <add name="HttpSoap"/>
        <add name="HttpPost"/>
        <add name="HttpGet"/>
        <add name="Documentation"/>
      </protocols>
    </webServices>

在我印象中vs.net2003好像没这么麻烦,这估计和vs.net2005的安全级别有关系。

顺便写一个利用web service获取客户端IP的例子

[WebMethod(Description = "通过Web service获取客户端的IP")]
    public string GetIP()
    {
        string ip;
        if (Context.Request.ServerVariables["HTTP_VIA"] != null)
        {
            ip = Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
        }
        else
        {
            ip = Context.Request.ServerVariables["REMOTE_ADDR"].ToString();
        }
        return ip;
    }

posted on 2010-11-22 08:59  苍茫大地NV  阅读(646)  评论(0编辑  收藏  举报