0

我有一个 wcf 服务并使用控制台应用程序作为我的服务的主机。当我使用这样的基地址时:<baseaddres ="http://ipaddress:8080/" />. 当我通过 Web 浏览器检查我的服务操作时,我可以打开服务 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();
        }
    }
4

1 回答 1

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>

于 2014-07-16T01:21:36.713 回答