WCF服务与localhost一起使用,但不与IP地址一起使用

时间:2013-07-05 20:00:44

标签: wcf

我查看了其他类似的问题,但未能解决我自己的问题。

我有一个WCF服务,如果我连接到它的话可以工作:

http://localhost:35001/SchoolLightService.svc

但是如果我使用计算机的IP地址(来自局域网内),则不然:

http://192.168.1.4:35001/SchoolLightService.svc

错误信息是(必须将ip号码(上面一个)更改为“my ip”以取悦Stackoverflow):

  

错误:无法从中获取元数据   http://“my ip”:35001 / SchoolLightService.svc如果这是一个Windows   (R)请访问您的通信基金会服务   检查您是否已在指定的位置启用元数据发布   地址。有关启用元数据发布的帮助,请参阅   MSDN文档在   http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata交流   错误URI:http://“my ip”:35001 / SchoolLightService.svc
  元数据包含无法解析的引用:   'http://“my ip”:35001 / SchoolLightService.svc'。没有   端点侦听http://“my ip”:35001 / SchoolLightService.svc   那可以接受这个消息。这通常是由不正确引起的   地址或SOAP操作。有关更多信息,请参阅InnerException(如果存在)   细节。无法连接到远程服务器无连接   可以制作,因为目标机器主动拒绝它   “my ip”:35001HTTP GET错误URI:http://“my ip”:35001 / SchoolLightService.svc出现错误   下载'http://“my ip”:35001 / SchoolLightService.svc'。
  无法连接到远程服务器无法建立连接   因为目标机器主动拒绝它“我的IP”:35001

web.config看起来像:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="SLBehavior">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpGetUrl="" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services >
      <service name="SchoolLightWCF.SchoolLightService"
              behaviorConfiguration="SLBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://192.168.1.4:35001" />
          </baseAddresses>
        </host>
        <endpoint
          address="/SchoolLightService"
          binding="wsHttpBinding"
          contract="SchoolLightWCF.ISchoolLightService"
        />
        <endpoint
           address="mex"
           binding="mexHttpBinding"
           contract="IMetadataExchange"
        />
      </service>

    </services>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <diagnostics>

      <messageLogging
       logMessagesAtTransportLevel="true" logMessagesAtServiceLevel="false"
            logMalformedMessages="true" logEntireMessage="true"
            maxSizeOfMessageToLog="65535000" maxMessagesToLog="500" />

    </diagnostics>
  </system.serviceModel>
  <system.diagnostics>
    <sharedListeners>
      <add name="sharedListener"
        type="System.Diagnostics.XmlWriterTraceListener"
        initializeData="c:\temp\tracelog.svclog" />
    </sharedListeners>
    <sources>
      <source name="System.ServiceModel" switchValue="Verbose, ActivityTracing" >
        <listeners>
          <add name="sharedListener" />
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
        <listeners>
          <add name="sharedListener" />
        </listeners>
      </source>
      <source name="ApplicationLogging" switchValue="Information" >
        <listeners>
          <add name="sharedListener" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true" />
  </system.webServer>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
  <connectionStrings>
    <add name="SLEntities" connectionString="...not relevant..." />
  </connectionStrings>
</configuration>

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我通过将其发布到计算机上运行的真实IIS服务器来解决它。出于某种原因,Visual Studio中的内置Web服务器没有删除它。