Wcf服务主机在另一台计算机上

时间:2014-04-28 13:28:46

标签: c# .net wcf service

我找到了一些关于此的话题,但我无法找到解决方法。 当我在同一台机器上托管我的WCF服务时,一切都很好。但是当我将它托管在另一台机器上而不是客户机上时会出现问题

当我从客户端调用Open函数时,会发生超时异常。

服务器端配置:

        <service name="Connectors.AppConnector">
        <endpoint address="" binding="customBinding" bindingConfiguration="MessageBinding" 
          contract="Contracts.IServiceContract">

        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="<ADDRESS>/MessengerService" />
          </baseAddresses>
        </host>
      </service>

   <customBinding>
        <binding name="MessageBinding">
          <reliableSession />
          <compositeDuplex />
          <oneWay />
          <textMessageEncoding
                         messageVersion="Soap12WSAddressing10"
                         writeEncoding="utf-8" />
          <httpTransport authenticationScheme="Anonymous"
                         bypassProxyOnLocal="false"
                         hostNameComparisonMode="StrongWildcard"
                         proxyAuthenticationScheme="Anonymous"
                         realm=""
                         useDefaultWebProxy="true" />
        </binding>
      </customBinding>

服务端代码:

ServiceHost host = new ServiceHost(manager.AppConnector);
host.Open();

以前我有简单的wsdualhttpbinding来支持回调,但是找到这样的解决方案来关闭安全性。

客户端配置:

<?xml version="1.0"?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
    <system.serviceModel>
        <bindings>
            <wsDualHttpBinding>
                <binding name="CustomBinding_IServiceContract">
                    <security mode="None" />
                </binding>
            </wsDualHttpBinding>
        </bindings>
        <client>
            <endpoint address="<ADDRESS>/MessengerService"
                binding="wsDualHttpBinding" bindingConfiguration="CustomBinding_IServiceContract"
                contract="ServiceReference1.IServiceContract" name="CustomBinding_IServiceContract" />
        </client>
    </system.serviceModel>
</configuration>

客户端代码:

public class TestClass : IServiceContractCallback
{
    public void Start()
    {

        InstanceContext context = new InstanceContext(this);
        ServiceContractClient client = new ServiceContractClient(context);
        Console.WriteLine("Opening");
        client.Open();
        Console.WriteLine("Opened");
    }

    public void MessageReceived(ServiceMessage message)
    {
        throw new NotImplementedException();
    }

    public void MessageStatus(ServiceStatus status)
    {
        throw new NotImplementedException();
    }
}

每次尝试与客户端连接时都会抛出TimeoutException。服务器端的防火墙已关闭,我可以使用浏览器进入/ MessengerService。 有什么问题?

0 个答案:

没有答案