将React网站托管在与WCF服务相同的文件夹中

问题描述

我已经通过GoDaddy在共享的Windows主机上设置了现有的WCF服务,我希望将react应用上传到同一主机上以使用该服务。

例如,我在https://example.com/Service1.svc/处设置了服务,当您输入https://example.com时,我希望react应用程序可见,并且仍然能够通过现有的url访问该服务。

我不确定如何配置我的web.config来满足此要求。导航到根域会给我一个404错误,尽管文件已经存在,但尝试导航到index.html也会出错。如果我清除了web.config,则反应站点正常工作,但显然该服务不再起作用。

以下是我的网络配置:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <trust level="Full" originUrl="" />
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="50000000" />
      </webServices>
    </scripting>
  </system.web.extensions>
  <system.serviceModel>
    <services>
      <service name="MyService.Service1" behaviorConfiguration="web">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="httpBinding"
          contract="MyService.IService1" />
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="httpsBinding"
          contract="MyService.IService1" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="web">
          <serviceMetadata httpGetEnabled="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp helpEnabled="true" defaultBodyStyle="Bare" faultExceptionEnabled="true"
            automaticFormatSelectionEnabled="true" />
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
    <bindings>
      <webHttpBinding>
        <binding name="httpBinding">
          <security mode="None" />
        </binding>
        <binding name="httpsBinding">
          <security mode="Transport" />
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
        <add name="Access-Control-Allow-Headers" value="Content-Type" />
      </customHeaders>
    </httpProtocol>
    <staticContent>
      <clear />
      <mimeMap fileExtension="." mimeType="*/*" />
      <mimeMap fileExtension=".txt" mimeType="*/*" />
      <mimeMap fileExtension=".json" mimeType="application/json" />
    </staticContent>
  </system.webServer>
</configuration>

或者,我发现我可以将服务放在子文件夹中并配置一个虚拟目录,以便它可以在其中运行,但是将服务的URL更改为http://example.com/subfolder/Service1.svc,这在当前阶段是不可取的。有什么办法可以使原始URL以某种方式指向子文件夹中的服务?

任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)