开发者

Accessing web services localhost from computer on network

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?

开发者_JAVA百科

Thank you very much.


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.


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


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.


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.


.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜