wcf服务主机仅在端口号8080上运行

时间:2014-06-25 15:29:30

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

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

但是,当我将端口号更改为其他内容时。服务主机正常启动(使用的端口号或其他任何内容除外)。当我去检查服务是否通过Web浏览器运行时,服务未显示。最终我的客户也无法找到该服务。

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();
        }
    }

1 个答案:

答案 0 :(得分:0)

<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>