【问题标题】:How to host a public WCF service?如何托管公共 WCF 服务?
【发布时间】:2012-11-19 00:34:14
【问题描述】:

我正在尝试创建一个 tcp wcf 服务,该服务将托管在没有 IIS 的服务器上,并且无需身份验证即可供公众访问。

这是我的工作:

ServiceHost svh = new ServiceHost(typeof(MyService));

var tcpbinding = new NetTcpBinding(SecurityMode.None);

var location = "net.tcp://localhost:11111";
svh.AddServiceEndpoint(typeof(IMyService), tcpbinding, location);

svh.Open();
....

该服务在 locashost 上运行良好,但是当我在服务器上设置它时(添加了防火墙异常),客户端崩溃并显示一条消息:

The socket connection was aborted. This could be caused by an error processing 
your message or a receive timeout being exceeded by the remote host, or an 
underlying network resource issue. Local socket timeout was '00:00:59.7344663'.

这是客户端配置文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="NetTcpBinding_IMyService">
                    <security mode="None" />
                </binding>
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://myserver:11111/"
                binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IMyService"
                contract="MyServer.IMyService" name="NetTcpBinding_IMyService" />
        </client>
    </system.serviceModel>
</configuration>

我应该改变什么才能让它工作?

【问题讨论】:

标签: c# wcf


【解决方案1】:

我过去遇到过类似的问题,我通过不在端点地址 (ServiceHost .ctor) 中使用 localhost 解决了它,而是使用了实际的机器名称。另外,您可以在服务主机本身中定义地址,如下所示。

ServiceHost svh = new ServiceHost(typeof(MyService), new Uri("net.tcp://myserver:11111"));
var tcpbinding = new NetTcpBinding(SecurityMode.None);
svh.AddServiceEndpoint(typeof(IMyService), tcpbinding, "");
svh.Open();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多