从网络上的计算机访问 Web 服务 localhost

发布于 2024-08-19 10:31:28 字数 236 浏览 8 评论 0原文

我正在尝试开发一个 iPhone 应用程序来使用用 C# 编写的 Web 服务。我希望能够通过我的 PC 上的本地主机访问网页 (http://localhost:54053/Service1 .asmx),所以我还不必立即推送 Web 服务。关于如何做到这一点有什么建议吗?

非常感谢。

I'm trying to develop an iPhone application to consume a Web Service written in C#. I want to be able to access the web page through the localhost on my PC (http://localhost:54053/Service1.asmx) so I don't have to push the Web Service live just yet. Any recommendations on how to do this?

Thank you very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

自由如风 2024-08-26 10:31:28

您必须在开发计算机上使用 IIS。内置的Cassini服务器直接绑定到127.0.0.1,只能在本地访问。要从远程设备访问它,您需要在 IIS 中设置主机。 Cassini 的限制为 127.0.0.1,无法远程访问。

一旦您将网站设置为响应非 127.0.0.1 的 IP 地址,并且将其配置为为您的新 Web 服务提供服务,您就可以使用该 IP 地址来访问该网站。

You will have to use IIS on your development machine. The built-in Cassini server binds directly to 127.0.0.1 and is only accessible locally. To access it from a remote device, you need to set up a host in IIS. Cassini has a limitation to 127.0.0.1 and is not accessible remotely.

Once you have a website set up to answer to an IP address that is not 127.0.0.1, and it's configured to serve your new web service, then you can use the IP address to get to it.

与他有关 2024-08-26 10:31:28

首先让它像

http://localhost/Service1.asmx

一样工作要做到这一点,你必须让你的网络服务在本地 IIS 中工作。

然后找到你本地机器的IP。

www.whatismyipd.com

然后确保端口 80 已打开(如果您不确定如何执行此操作,请尝试关闭 Windows 防火墙)

然后使用您的 IP 地址调用 Web 服务:
http://xxx.xxx.xxx.xxx/Service.asmx

First make it work like

http://localhost/Service1.asmx

To do this you have to make your web service work within local IIS.

Then find the Ip of your local machine.

www.whatismyipd.com

Then be sure that the port 80 is open (If you're not sure how to do this try switching the windows firewall off)

Then call the web service with your IP address as:
http://xxx.xxx.xxx.xxx/Service.asmx

嗳卜坏 2024-08-26 10:31:28

我假设您有一部手机或在 Mac 上运行的模拟器。这意味着它们与在 asp.net 中开发的 Web 服务不在同一台计算机上。

您需要将“localhost”更改为您的计算机可以访问的IP。您可以通过运行“ipconfig”来完成此操作。如果 mac 与您的服务位于同一本地网络上,则可能是 192.xxx 或 10.xxx 等。

例如: http://192.168.1.20:54053/Service1.asmx 将是地址在我的本地网络上。

如果您需要使用互联网地址,那就要复杂得多,因为您很可能必须打开防火墙端口并在网关/路由器上进行端口转发。

I assume you either have a phone or emulator running on a mac. This means they are not on the same machine as your webservice which is developed in asp.net.

You need to change "localhost" to an IP your computer can be reached at. You can do this by running "ipconfig". If the mac is on the same local network as your service this is probably 192.x.x.x something or 10.x.x.x something.

Eg.: http://192.168.1.20:54053/Service1.asmx would be the address on my local network.

If you need to use an internet address it's much more complex, since you most likely have to open firewall ports and do port forwarding at a gateway/router.

陪你到最终 2024-08-26 10:31:28

内置的Cassini服务器直接绑定到127.0.0.1,只能在本地访问。

你可以尝试一个技巧
将套接字附加到您的本地主机 Web 服务地址,

var localSocket =new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
               localSocket .Connect(new IPEndPoint(IPAddress.Loopback, localPortnumber));

然后将套接字绑定到 IpEndPoint,

 Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                listener.Bind(new IPEndPoint(IPAddress.Any, 8080));

然后以客户端服务器方式访问您的 Web 服务。

完整的工作示例可以在此处查看。


The built-in Cassini server binds directly to 127.0.0.1 and is only accessible locally.

You can try a trick
Attach a socket to your localhost web service address like that

var localSocket =new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
               localSocket .Connect(new IPEndPoint(IPAddress.Loopback, localPortnumber));

Then bind a socket to IpEndPoint like that

 Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                listener.Bind(new IPEndPoint(IPAddress.Any, 8080));

And then access your web service in a client server fashion.

A complete working example can be seen here.


.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文