【问题标题】:wcf service host run only on port number 8080wcf 服务主机仅在端口号 8080 上运行
【发布时间】:2014-06-25 15:29:30
【问题描述】:

我有一个 wcf 服务并使用控制台应用程序作为我的服务的主机。当我使用这样的基地址时:<baseaddres ="http://ipaddress:8080/" />。当我通过网络浏览器检查我的服务操作时,我可以打开服务 WSDL,它工作正常。

但是,当我将端口号更改为其他值时。服务主机启动正常(使用的端口号或其他任何东西都不例外)。当我去检查服务是否通过网络浏览器运行时,服务没有显示。最终我的客户也找不到该服务。

app.config 配置

    <services>
  <service name="Natatorium_WCF.NatatoriumService"
           behaviorConfiguration="ServiceBehavior">
    <endpoint address="NatatoriumService"
              binding="wsHttpBinding"
              contract="Natatorium_WCF.INatatoriumService"
              bindingConfiguration="wsHttpBindingConfig">
    </endpoint>
    <endpoint address="NatatoriumService"
              binding="netTcpBinding"
              contract="Natatorium_WCF.INatatoriumService"
              bindingConfiguration="netTcpBindingConfig" >
    </endpoint>
    <endpoint address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange"/>
    <host>
      <baseAddresses>
        <add baseAddress="http://[ServerName]:[PortNO.1]"/>
        <add baseAddress="net.tcp://[ServerName]:[PortNO.2]"/>
      </baseAddresses>
    </host>
  </service>
</services>

这是启动服务(控制台应用程序)的主机代码。

 static void Main(string[] args)
    {
        ChangeServerConfigFileAttributeValue("8080", "8090");
        using (ServiceHost host = new ServiceHost(typeof(Natatorium_WCF.NatatoriumService)))
        {
            host.Open();
            Console.WriteLine("Listening...");
            Console.ReadLine();
        }
    }

【问题讨论】:

  • 您有防火墙或端口限制吗?
  • 我不知道如何检查防火墙,顺便说一下我的防火墙已关闭@TMcKeown
  • 你认为它应该如何受到配置的影响,因为它只适用于 +/8080 端口号 @paramosh
  • 我在上面的帖子中添加了我的配置设置。我已经使用了令牌并在运行时自动设置了 IP 地址和端口号。 @paramosh
  • 配置本身看起来不错。可能与启动主机的代码有关。

标签: c# web-services wcf port-number


【解决方案1】:
<configuration>
<system.serviceModel>
<services>

  <service name="HelloService.HelloService" behaviorConfiguration="mexBehaviour">
    <endpoint address="HelloService" binding="basicHttpBinding" contract="HelloService.IHelloService" ></endpoint>
    <endpoint address="HelloService" binding="netTcpBinding" contract="HelloService.IHelloService" ></endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8080/"/>
        <add baseAddress="net.tcp://localhost:8090/"/>
      </baseAddresses>
    </host>

  </service>

</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="mexBehaviour">
      <remove name="serviceDebug"/>
      <serviceMetadata httpGetEnabled="true"/>
    </behavior>
  </serviceBehaviors>


</behaviors>

【讨论】:

  • 我的错误与我在 appconfig 上编写的代码相同
猜你喜欢
  • 2019-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多