注册 登录
编程论坛 WCF论坛

WCF http访问,localhost可以,但通过ip地址访问就不行。

Low_Grandle 发布于 2017-09-18 15:26, 4460 次点击
做了一个wcf的程序,通过http访问,localhost可以正常访问,但换成ip地址就不行了。
求指点,这是config的内容

防火墙已经关闭了

程序代码:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- 部署服务库项目时,必须将配置文件的内容添加到
  主机的 app.config 文件中。System.Configuration 不支持库的配置文件。-->
  <system.serviceModel>

    <bindings>
      <webHttpBinding>
        <binding name="HttpJsonBinding" crossDomainScriptAccessEnabled="true"/>
      </webHttpBinding>
    </bindings>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
    <services>
      <service name="JsonServerDLL.JsonServer">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="HttpJsonBinding"
          contract="JsonServerDLL.IJsonServer">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8736/JsonServer/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 为避免泄漏元数据信息,
          请在部署前将以下值设置为 false 并删除上面的元数据终结点  -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- 要接收故障异常详细信息以进行调试,
          请将以下值设置为 true。在部署前设置为 false
            以避免泄漏异常信息-->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>
2 回复
#2
Low_Grandle2017-09-18 15:27
winform 做的宿主- -
#3
w11490507212020-07-13 15:53
<add baseAddress="http://localhost:8736/JsonServer/" />

改一下  localhost 改成你电脑实际的Ip 或者 主机名试一下
1