简体   繁体   English

在本地主机时如何调用Web服务

[英]How to call a webservice when in localhost

I do not have IIS, I use my localhost that comes with Visual Studio, I am not sure how to make a service call work if I am using localhost. 我没有IIS,使用的是Visual Studio随附的本地主机,如果使用本地主机,我不确定如何使服务调用正常工作。 It tells me "Unable to connect to remote server" , Is there a way I can make a webservice call work using localhost?. 它告诉我“无法连接到远程服务器”,是否可以使用localhost进行Web服务调用? Here is my code: 这是我的代码:

    public void CallService()
    {
        WebRequest requestweb = WebRequest.Create("http://localhost/WebServices/MyTestService/HelloWorld");
        requestweb.Method = "GET";
        //Line below returns "Unable to connect to remote server"
        WebResponse response = requestweb.GetResponse();
        Console.WriteLine(((HttpWebResponse)response).StatusDescription);
        Stream data = response.GetResponseStream();
        response.Close();
    }

Would truly appreciate an advice on this. 非常感谢您提出建议。 Thank you 谢谢

Open the website you're trying to connect to in your favorite web browser. 在您喜欢的网络浏览器中打开您要连接的网站。 Copy the value from your location bar and paste it as the parameter to WebRequest.Create . 从位置栏中复制该值,并将其作为参数粘贴到WebRequest.Create

You can use a simple Java TCP tunnel. 您可以使用简单的Java TCP隧道。

Download this Java app & just tunnel the traffic back. 下载 Java应用程序,然后将流量通过隧道传输回去。

In command prompt, you'd then run the java app like this... Let's assume you want external access on port 80 and your standard debug environment runs on port 1088... 在命令提示符下,您将像这样运行Java应用程序...假设您想在端口80上进行外部访问,而标准调试环境则在端口1088上运行...

java -jar tunnel.jar 80 localhost 1088

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM