【问题标题】:localhost refusing connection in WCFlocalhost拒绝WCF中的连接
【发布时间】:2016-11-10 15:55:48
【问题描述】:

我在使用控制台应用程序托管 WCF 时正在学习 WCF(C#)。它没有显示任何错误,但是当我在浏览器浏览器中输入http://localhost:8080/ 时说它拒绝连接。请给我解决方案。enter image description here

我在配置文件中的代码如下

    <services>
  <service name="MyService.MyWService" behaviorConfiguration="mexBehaviour">
    <endpoint address="HelloService" binding="basicHttpBinding" contract="MyService.IMyWService">
    </endpoint>
    <endpoint address="HelloService" binding="netTcpBinding" contract="MyService.IMyWService">
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8080" />
        <add baseAddress="net.tcp://localhost:8090"/>
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="mexBehaviour">
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

【问题讨论】:

  • 在本地主机前添加http://
  • 试过了,没用
  • 我发现了问题。这是因为我在控制台应用程序中托管 wcf 并且我没有通过使用 console.readline() 命令保持它的活动状态,这就是 localhost 不起作用的原因。它只存活了几毫秒

标签: c# .net visual-studio wcf configuration-files


【解决方案1】:

您遇到的错误是由于浏览器无法找到网站 localhost。您应该使用以下格式访问 localhost 地址。

http[s]://localhost:&lt;port number&gt;

您还可以通过访问 127.0.0.1 来查看本地主机地址,这是您本地主机的环回地址。

127.0.0.1:8080

【讨论】:

    猜你喜欢
    • 2018-10-17
    • 2021-02-20
    • 2023-02-05
    • 1970-01-01
    • 2012-06-05
    • 2019-08-20
    • 2021-09-25
    • 1970-01-01
    • 2017-04-11
    相关资源
    最近更新 更多