【发布时间】: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