我有客户端和服务端的WCF项目,我试图在IIS服务上部署它。我看了很多关于如何做到这一点的教程和视频,但所有这些都与我的代码不同。在服务代码
中DPL.Service.Host使用FACADE,DAL,COMMON和BL并且拥有所有引用我没有.svc文件,但我读到它可以像新的一样编写
ServiceHost( typeof( MyNamespace.MyServiceImplementationTypeName ) )
并且确实如何编写服务的代码是:
using DPL.Server.BL;
using DPL.Server.Common.Providers;
using DPL.Server.Facade;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
namespace DPL.Server.Host
{
public partial class Service1 : ServiceBase
{
internal static ServiceHost myServiceHost = null;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try
{
if (null != myServiceHost)
{
myServiceHost.Close();
}
LogFileProvider.WriteLine("Service Started");
myServiceHost = new ServiceHost(typeof(DPLService));
myServiceHost.Open();
LogFileProvider.WriteLine("Run Core.StartBL()");
Core.StartBL();
LogFileProvider.WriteLine("Service OnStart Done!");
}
catch (Exception e)
{
LogFileProvider.WriteException(99, "OnStart", e);
throw;
}
}
protected override void OnStop()
{
if (null != myServiceHost)
{
myServiceHost.Close();
myServiceHost = null;
}
}
}
}
我有配置文件app.config,我不确定它是否有利于IIS服务器在localhost上运行。代码是:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- ____________________________________________________________ Data Base Connection _____________________________________________________________________ -->
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="DPL.Server.Facade.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings>
<!--<add name="DPL_SqlServer" connectionString="server='PROSQL01' ;database=Dpl ;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />-->
<add name="DPL_SqlServer" connectionString="server='(local)\SQLEXPRESS'
 ;database=Dpl
 ;Integrated Security=SSPI;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<!-- ____________________________________________________________ WCF Configuration _____________________________________________________________________ -->
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.web>
<compilation debug="true" />
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="DPL.Server.Facade.DPLService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding"
contract="DPL.Server.Facade.IDPLService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8722/DPLService" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00">
<readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="True" />
<dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Common" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<userSettings>
<DPL.Server.Facade.Properties.Settings>
<setting name="UseMockBl" serializeAs="String">
<value>False</value>
</setting>
</DPL.Server.Facade.Properties.Settings>
</userSettings>
</configuration>
如果有人可以帮我解决这个问题,我会感到非常高兴
p.s我在虚拟机框中运行win server 2016并在那里下载了IIS服务器
感谢
安德烈