使用托管为Windows服务的WCF

时间:2011-08-26 05:02:11

标签: vb.net wcf forms install

我在Windows服务中构建并安装了WCF服务(带安装程序)。打开管理工具,服务,并毫无问题地启动服务。

所以现在我开始一个新项目(一个简单的Windows表单应用程序)。我想消耗我的新WCF,但不知道如何。我似乎无法添加引用/添加服务引用。

非常感谢任何帮助。

谢谢, 杰森

1 个答案:

答案 0 :(得分:1)

当托管WCF服务的Windows服务启动并正常运行并正确配置时,您应该能够使用Visual Studio的Add Service Reference或命令行svcutil工具连接到该服务。

只需输入服务所在的地址即可。

这要求您的服务启用元数据交换(作为服务行为),并在其配置中提供至少一个MEX(元数据交换)端点。你有那些吗?

服务行为:

<behaviors>
   <serviceBehaviors>
       <behavior name="mex">
           <serviceMetadata />
       </behavior>
   </serviceBehaviors>
</behaviors>

然后您的服务必须引用此配置。

服务配置:

<services>
    <service name="YourService" 
        behaviorConfiguration="mex">  <!-- reference the service behavior with the serviceMetadata element ->
        <endpoint .... (your regular endpoint here)  />
        <endpoint name="mex"
            address="mex"
            binding="mexHttpBinding"
            contract="IMetadataExchange" />
    </service>
</services>