WCF侦听基址anyip [英] WCF listen base address anyip

查看:121
本文介绍了WCF侦听基址anyip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的服务主机具有任何IP的基地址 所以我尝试了

i want my servicehost to have the base address of any IP so i tried this

new ServiceHost(typeof(LoggingController),new Uri("0.0.0.0"));

它给了我无效的URI格式

and it gives me invalid URI format

有人知道我该怎么写吗?

any one knows how should i write this ?

好吧,我尝试从本地局域网外部访问它,但没有成功,我使用tcpiplistener制作了一个小型测试软件,并开始侦听相同的端口,并将tcpip协议的基址设置为anyip和小型测试软件正常工作,所以我发现我需要做的就是为Webservice设置相同的内容–

well i tried to access it from outside of my local lan and it didnt work , i made a small test software using tcpiplistener and i started listening to the same port and i set the base address of the tcpip protocol to anyip and the small test software worked so i figured out all i need to do is setting the same for the Webservice –

TcpListener tcpListener = new TcpListener(IPAddress.Any,10021);

这有效,这也意味着我的系统管理员已经做了工作,以确保可以从外部访问端口/服务器,现在我的网络服务不应该工作!它可以工作,但是我不能从外部访问它,如果我在同一台PC上运行客户端,则可以从同一台PC上访问它.

this works which also mean my system admin did his job of making sure the port/server is accessable from outside, now shouldnt my webservice work !? it work but i cant access it from outside , i can access it from the same pc if i run client on the same pc

推荐答案

在类似的情况下,以下代码对我有用:

The following code works for me in a similar situation:

Uri baseAddress = new Uri("net.tcp://0.0.0.0:8080/MyService");
host = new ServiceHost(typeof(MyServer), baseAddress);

这篇关于WCF侦听基址anyip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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