localhost拒绝WCF中的连接

时间:2016-11-10 15:55:49

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

我正在学习WCF(C#),而我正在使用控制台应用程序托管WCF。它显示没有错误,但是当我在浏览器浏览器中输入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>

1 个答案:

答案 0 :(得分:0)

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

http[s]://localhost:<port number>

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

127.0.0.1:8080