无法使用Asp .Net访问Web服务. [英] Unable to access a web Service using Asp .Net.

查看:78
本文介绍了无法使用Asp .Net访问Web服务.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,

我创建了一个简单的Web服务,并尝试从asp .net访问它.但是我收到一条错误消息,"WebException未由用户代码处理.无法连接到远程服务器."以前它工作正常.我认为某些设置已更改.我也重新安装了.net.仍然不起作用.

我也无法发送电子邮件.我收到了同样的错误提示无法连接到远程服务器"

请帮我解决这个问题.


这是我的代码
-----------------

Sir,

I have created a simple web service and trying to access it from asp .net. But i am getting an error message that "WebException was unhandlled by user code . Unable to connect to the remote server." Previously it was working properly. I think some setting hag been changed. I have reinstalled .net also. Still it is not working.

I am not able to send email also. I am getting same error lile "Unable to connect to remote server"

Plz help me how can i rectify this problem.


This is my Code
-----------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

/// <summary>
/// Summary description for ws
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class ws : System.Web.Services.WebService {

    public ws () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }
    
}

 protected void Page_Load(object sender, EventArgs e)
    {
        helloworldws.ws obj = new helloworldws.ws();
        string result = obj.HelloWorld();
        Response.Write(result);
    

    }

推荐答案

如果无法按计算机名称浏览,则意味着您有网络问题需要解决.例如,它可能是阻止远程连接的防火墙设置.或者,也许您的Web服务是由VS的测试主机而不是IIS托管的.您必须使用IIS进行托管,因为VS测试主机根本不允许远程连接.

127.0.0.1和localhost(实际上是相同的)将永远无法工作,因为设备/仿真器会尝试连接到自身,而我严重怀疑您是否设法将IIS安装到设备上并在其上运行WS.
If you cannot browse by machine name it means you have networking issues to resolve. For example it can be firewall settings preventing remote connections. Or, perhaps, your web service is hosted by VS''s test host and not by IIS. You must use IIS for hosting as VS test host does not allow for remote connections at all.

127.0.0.1 and localhost (which is indeed the same) would never work as device/emulator would try to connect to itself and I seriously doubt you’ve managed to install IIS on to the device and running WS on it.


这篇关于无法使用Asp .Net访问Web服务.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆