以下是我对如何托管wcf库项目的理解。创建wcf库项目后,您将获得app.config,如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</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="WcfLib.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8732/Design_Time_Addresses/WcfLib/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="wsHttpBinding" contract="WcfLib.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
您可以简单地创建一个空控制台应用程序项目(只需在其中添加Console.ReadLine()
),并添加对上一个项目程序集的引用,并添加整个{{1} }标签如上所示。现在它托管了。只要控制台应用程序存在,它就会存在。
注意标记是如何编写标记以使其工作的。 services
中的所有内容代表要托管的wcf服务实体。在这种情况下,托管是通过我的控制台应用程序通过conifugration完成的。
我正在考虑是否可以按照类似的方式进行wcf服务消费。我可以使用相同的配置模式编写我的wcf客户端吗?最后,我期待将这些配置放在单独的配置文件中。
Here are links of previous posts if you are interested in what made me ask this question
答案 0 :(得分:1)
您的服务不会自行托管。 调试WCF库时,调试器将运行WCF服务主机来托管您的服务。您必须在真实环境中手动执行此操作。
了解WCF服务主机here。
修改强>
回答您的问题:是的,您可以以相同的方式配置您的客户。见this article
答案 1 :(得分:0)
我遇到了以下SO帖子。也许我的答案在于:或不是......我不确定
How to tell WCF client to read settings out of different config file?