简体   繁体   English

将带有WCF的WebForms部署到IIS 8中不会启动WCF

[英]Deploying a WebForms with WCF inside to IIS 8, doesn't start WCF

I have a VisualStudio solution with WebForms (called EDWMS) & WCF projects (called EDWMS.SYNC) inside. 我有一个VisualStudio解决方案,其中包含WebForms(称为EDWMS)和WCF项目(称为EDWMS.SYNC)。 WCF is added as Service Reference to WebForms project by using Discover function. 使用发现功能将WCF添加为WebForms项目的服务参考。 When running it locally in "release" mode, the WCF gets called correctly from app & works fine (though I need to run VS as Administrator for it to work). 在“发布”模式下本地运行时,可以从应用程序正确调用WCF并正常运行(尽管我需要以管理员身份运行VS才能正常工作)。 But when publishing the webforms project to IIS 8 both via Web Deploy Package & FTP Publish, WCF doesn't seem to get published. 但是,当通过Web Deploy Package和FTP Publish将Webforms项目发布到IIS 8时,WCF似乎没有发布。

I tried to create WCF as a separate Site in IIS, then setting WCF project as "Startup project" in VS & publishing it to new site slot, also adding it's port to the site bindings. 我试图在IIS中将WCF创建为单独的站点,然后在VS中将WCF项目设置为“启动项目”,并将其发布到新站点插槽中,并将其端口添加到站点绑定中。 In this case I can browse .svc file & see that it's set up You have created a service. 在这种情况下,我可以浏览.svc文件并查看它的设置。 您已经创建了服务。 To test this service, you will need... . 要测试此服务,您将需要...。 But when I call it from WebForms app it still fails to respond with this error: 但是,当我从WebForms应用程序调用它时,它仍然无法响应此错误:

There was no endpoint listening at http://localhost:8733/Design_Time_Addresses/ED_WMS.SYNC/Sync/ that could accept the message. This is often caused by an incorrect address or SOAP action.
The remote server returned an error: (404) Not Found.

This is code from WebForms app which calls WCF: 这是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;

This is my WebForms Web.config : 这是我的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>

This is my WCF App.config : 这是我的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>

When you move from DEV -> Production( when the WCF app is now hosted in IIS), the design time URL changes, you would need to set the correct designTime URL in your webforms app now. 当您从DEV-> Production(现在将WCF应用程序托管在IIS中)移动时,设计时间URL会更改,您现在需要在Webforms应用程序中设置正确的designTime URL。

A few options are available, but they all point to changing the URI that is associated with the service 有一些选项可用,但是它们都指向更改与服务关联的URI。

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

Where the TestURI is the designTime URL, and the LiveURL is the production URL. 其中TestURI是designTime URL,而LiveURL是生产URL。 The IsLiveServer is just a boolean to check if you are in dev or production. IsLiveServer只是检查您是否在开发或生产中的布尔值。

The other way you can go about it is to just to create a Realease vs a Debug webconfig, the release will have the URL of the deployed App, then set the client Endpoint using an appSetting or something similar 您可以使用的另一种方法是仅创建Realease与Debug Webconfig,该发行版将具有已部署的App的URL,然后使用appSetting或类似方法设置客户端端点

The third option would require using the IIS Administration DLL to query the hosted website and findout the URL of the WCF service and use that in your webforms. 第三个选项将需要使用IIS管理 DLL来查询托管网站,并找到WCF服务的URL并在您的Webforms中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM