无法访问远程服务器上的WCF服务

本文关键字:WCF 服务 服务器 访问 | 更新日期: 2023-09-27 17:59:57

我在使用basicHttpBinding运行的远程Windows VPS中托管WCF web服务C#。

问题是,我通过远程桌面浏览到服务器机器上的服务URL工作正常,但尝试使用外部IP地址(远程或EVEN本地)浏览不起作用。(它向我显示浏览器消息"无法访问此网站")示例:

http://localhost:99/Service1.svc(好)

http://8.35.36.82:99/Service1.svc从服务器的远程桌面(OK)

http://8.35.36.82:99/Service1.svc从我的机器(不正常)

我已经在服务器防火墙中打开了入站端口

有什么想法吗??

Web.config

  <system.serviceModel>
   <behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<services>
  <service name="WebService.Service1">
    <endpoint address="http://8.35.36.82:99/WebService/Service1.svc" binding="BasicHttpBinding" contract="WebService.IService1" />
  </service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false"  />
 </system.serviceModel>

无法访问远程服务器上的WCF服务

你能简单地把它放在你的配置中吗-->

<services>
  <service name="WebService.Service1">
    <endpoint address="" binding="BasicHttpBinding" contract="WebService.IService1" />
  </service>
</services>

我的解决方案

<system.serviceModel>
  <standardEndpoints>
      <webScriptEndpoint>
          <standardEndpoint name="webScriptEndpoint0" crossDomainScriptAccessEnabled="true" />
      </webScriptEndpoint>
  </standardEndpoints>
   <bindings>
    <basicHttpBinding>
      <binding name="basicHttpBinding0">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
          maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      </binding>
    </basicHttpBinding>
    <webHttpBinding>
      <binding name="webHttpBinding0">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
          maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      </binding>
    </webHttpBinding>
  </bindings>
  <services>
    <service behaviorConfiguration="debugServiceBehavior" name="Backend.CoreService">
      <endpoint address="" behaviorConfiguration="webHttpRest" binding="webHttpBinding"  bindingConfiguration="webHttpBinding0" name="Unsecure.Backend.CoreService"  contract="Backend.ICoreService" />
    </service>
  </services>
  <behaviors>
    <endpointBehaviors>
      <behavior name="webHttpRest">
        <webHttp helpEnabled="true" automaticFormatSelectionEnabled="true"  faultExceptionEnabled="true" />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="debugServiceBehavior">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <protocolMapping>
    <add binding="webHttpBinding" bindingConfiguration="basicHttpBinding0" scheme="http" />
  </protocolMapping>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>