【问题标题】:Deploying a WebForms with WCF inside to IIS 8, doesn't start WCF将带有 WCF 的 WebForms 部署到 IIS 8,不会启动 WCF
【发布时间】:2019-06-24 13:14:27
【问题描述】:

我有一个 VisualStudio 解决方案,其中包含 WebForms(称为 EDWMS)和 WCF 项目(称为 EDWMS.SYNC)。通过使用 Discover 功能将 WCF 作为服务引用添加到 WebForms 项目。当以“发布”模式在本地运行它时,WCF 会从应用程序中正确调用并且工作正常(尽管我需要以管理员身份运行 VS 才能使其工作)。 但是,当通过 Web 部署包和 FTP 发布将 webforms 项目发布到 IIS 8 时,WCF 似乎没有发布。

我尝试在 IIS 中将 WCF 创建为单独的站点,然后在 VS 中将 WCF 项目设置为“启动项目”并将其发布到新的站点插槽,并将其端口添加到站点绑定。在这种情况下,我可以浏览 .svc 文件并查看它是否已设置 您已创建服务。要测试此服务,您需要...。但是当我从 WebForms 应用程序调用它时,它仍然无法响应此错误:

在 http://localhost:8733/Design_Time_Addresses/ED_WMS.SYNC/Sync/ 上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。
远程服务器返回错误:(404) Not Found。 

这是来自 WebForms 应用程序的代码,它调用 WCF:

var client = new SyncClient("BasicHttpBinding_ISync");
client.InnerChannel.OperationTimeout = new TimeSpan(2, 00, 0);
var message = string.Empty;
try
{
    var syncResult = new SyncResult();
    syncResult = client.GetInventory(1, 2, 3);
    message += $"Sync Result<hr/>Added: {syncResult.ItemsAdded}<br/>Updated: {syncResult.ItemsUpdated}<br/>Duration: {syncResult.Duration}";
    ((ICommunicationObject)client).Close();
}
catch (System.Exception ex)
{
    (client as ICommunicationObject)?.Abort();
    message += $"Error<hr/>{ex?.Message ?? "null"}<hr/>{ex?.InnerException?.Message ?? "null"}";
}
inventoryItemsLbl.Text = message;

这是我的 WebForms Web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>...</connectionStrings>
  <appSettings>...</appSettings>
  <system.web>
    <authentication mode="Forms">
      <forms loginUrl="Login.aspx" timeout="2880" />
    </authentication>
    <compilation targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" executionTimeout="900" />
    <pages>...</pages>
  </system.web>
  <system.webServer><modules>...</modules></system.webServer>
  <runtime>...</runtime>
  <system.codedom><compilers>...</compilers></system.codedom>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
    </serviceHostingEnvironment>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ISync" />
      </basicHttpBinding>
    </bindings>
    <client>
<endpoint address="http://localhost:8733/Design_Time_Addresses/ED_WMS.SYNC/Sync/" 
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISync" 
contract="ServiceReferenceWMS.ISync" name="BasicHttpBinding_ISync" />
    </client>
  </system.serviceModel>
</configuration>

这是我的 WCF App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>...</configSections>
  <entityFramework>...</entityFramework>
  <runtime>...</runtime>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="MobilityBeanSoapBinding" closeTimeout="02:00:00" openTimeout="02:00:00"
            receiveTimeout="02:00:00" sendTimeout="02:00:00" maxReceivedMessageSize="100000000"
            maxBufferSize="100000000" maxBufferPoolSize="100000000">
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://warehouse:8080/wmwebservice_ejb/MobilityBean" binding="basicHttpBinding" bindingConfiguration="MobilityBeanSoapBinding" contract="EdWmsReference.MobilityBean" name="MobilityRemotePort" />
    </client>
    <services>
      <service name="ED_WMS.SYNC.Sync" behaviorConfiguration="MyServiceTypeBehaviors">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/ED_WMS.SYNC/Sync/" />
          </baseAddresses>
        </host>
        <endpoint name="basicHttpEndpoint" address="" binding="basicHttpBinding" contract="ED_WMS.SYNC.ISync" bindingConfiguration="MobilityBeanSoapBinding"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceTypeBehaviors" >
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

【问题讨论】:

  • 您是否偶然忘记了更改 Webforms 应用程序中的服务 URI?您可能在显式键入的 URI 上使用服务引用
  • @mahlatse 是的,在 VS 中,我将 WCF 添加为服务参考并通过此参考访问它。我需要在生产中更改某些内容吗?
  • 服务部署失败的原因
  • @mahlatse 你能解释一下我应该做什么吗?我是否需要删除我在 IIS 上为 WCF 创建的其他站点并重新部署主 WebForms 应用程序,然后编辑一些文件?
  • 我已经添加了一个关于你可以做什么的答案。

标签: c# asp.net wcf webforms iis-8


【解决方案1】:

当您从 DEV -> Production 迁移时(当 WCF 应用程序现在托管在 IIS 中时),设计时 URL 会发生变化,您现在需要在 Webforms 应用程序中设置正确的 designTime URL。

有几个选项可用,但它们都指向更改与服务关联的 URI

client.Endpoint.Address = new EndpointAddress(Server.IsLiveServer() ?
    @"LiveUrl" : @"TestURl"); 

其中 TestURI 是设计时间 URL,而 LiveURL 是生产 URL。 IsLiveServer 只是一个布尔值,用于检查您是处于开发阶段还是生产阶段。

您可以采取的另一种方法是创建一个 Realease vs Debug webconfig,发布将具有已部署应用程序的 URL,然后使用 appSetting 或类似的东西设置客户端端点

第三个选项需要使用IIS Administration DLL 来查询托管网站并找出 WCF 服务的 URL 并在您的 Web 表单中使用它。

【讨论】:

  • 将此添加到调用代码:client.Endpoint.Address = new EndpointAddress(@"http://localhost:8733/ED_WMS.SYNC.Sync.svc/"); 但现在我收到此错误:在建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供者:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例) 我的 WCF 没有链接到 SQL 服务器,它通过 SOAP 链接到仓库应用程序。
  • 似乎您的 SQL 连接错误或者您无法从发布位置连接到它,在设计时,URL 应该与生产不同,请检查您的 sql 连接字符串,看看它是否仍然有效
  • 看起来当单独部署为 2 个站点时,wcf 应用程序会丢失 webforms 应用程序的 sql 设置。我已将 webforms 中的 connstring 放入 wcf app.config,但现在当它尝试更新条目时出现错误,但 innerExceptions 中没有显示任何消息。有没有其他方法可以使用 wcf 部署应用程序而无需单独部署它们(在一个发布操作中,就像我在本地执行的那样)?
  • 在发布应用程序之前检查您的设置,有一个 debug web.config 和一个 release.webconfig,使用它们。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-11-26
  • 2011-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多