则@ServiceHost修改为:
<%@ ServiceHost Language="C#" Debug="true" Service="BruceZhang.WCF.DocumentsExplorerServiceImplementation.DocumentsExplorerService" Factory="BruceZhang.WCF.DocumentsExplorerIISHost.CustomServiceHostFactory"%>
在IIS托管应用程序中,我们需要创建web.config(注意,不是app.config),在<system.serviceModel>节中配置服务的相关内容:
<system.serviceModel>
<services>
<service behaviorConfiguration="DocumentExplorerServiceBehavior"
name="BruceZhang.WCF.DocumentsExplorerServiceImplementation.DocumentsExplorerService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="DocumentExplorerServiceBinding"
contract="BruceZhang.WCF.DocumentsExplorerServiceContract.IDocumentsExplorerService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="DocumentExplorerServiceBinding" sendTimeout="00:10:00" transferMode="Streamed" messageEncoding="Text" textEncoding="utf-8" maxReceivedMessageSize="9223372036854775807">
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="DocumentExplorerServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
注意,这里的配置文件与之前的宿主配置文件有个别的差异,就是没有指定服务的基地址。这是因为IIS托管会自动将svc文件的地址作为服务的基地址,我们无法在配置文件中自行指定。Svc文件的地址为svc文件在IIS虚拟目录或站点所设置的路径。例如,我们在IIS中创建一个虚拟目录DocumentsExplorer指向IIS宿主应用程序DocumentsExplorerIISHost,如图七所示:
