【发布时间】:2020-10-26 18:25:20
【问题描述】:
我查看了其他类似的问题,但无法解决我自己的问题。
我有一个 WCF 服务,如果我通过以下方式连接它就可以使用:
http://localhost:35001/SchoolLightService.svc
但如果我使用计算机的 IP 地址(来自 LAN 内)则不是:
http://192.168.1.4:35001/SchoolLightService.svc
错误信息是(必须将 ip 号(上面那个)更改为“我的 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://"我的 ip":35001/SchoolLightService.svc'。没有 端点监听 http://"my ip":35001/SchoolLightService.svc 可以接受该消息。这通常是由不正确的 地址或 SOAP 操作。有关更多信息,请参阅 InnerException(如果存在) 细节。无法连接到远程服务器 无连接 可以因为目标机器主动拒绝它 "my ip":35001HTTP GET Error URI: http://"my ip":35001/SchoolLightService.svc 出现错误 正在下载'http://"my ip":35001/SchoolLightService.svc'。
无法连接到远程服务器 无法建立连接 因为目标机器主动拒绝了它 "my 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>
我做错了什么?
【问题讨论】:
-
检查防火墙怎么样?
-
我为端口添加了入站规则,但没有效果。我确实有一个路由器,但这应该没关系,因为我只是在本地网络中工作,不是吗?
-
我尝试 telnet 到端口。如果我使用本地主机,它工作正常。如果我使用 IP 号(192.168.1.4),它无法连接。 Windows 防火墙被禁用,路由器设置了端口转发。
标签: wcf