1

我有一个 Windows 服务和一个表单,我需要它们进行通信。我访问的每个站点都指向 WCF。我尝试先在服务上实现它。像这样:

    protected override void OnStart(string[] args)
    {
        event_log.WriteEntry("TOPIAM_ADM: start");
        timer.Start();
        ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
    } 

这是与 WCF 相关的唯一行。当我启动服务时,它给了我这个错误

无法启动服务。System.InvalidOperationException:在 ServiceModel 客户端配置部分中找不到引用合同“ServiceReference1.IService1”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。在 System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName) 在 System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration) 在 System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName) 在 System.ServiceModel.ChannelFactory .InitializeEndpoint(String configurationName, EndpointAddress address) 在系统。1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) at System.ServiceModel.ConfigurationEndpointTrait1.System.ServiceModel.Config 处的 CreateSimplexFactory()...

我查了几个小时,但仍然不知道如何正确设置配置文件。

WCF 有自己的项目,服务有另一个项目,而那个 windows 窗体应用程序有另一个项目。我很确定它来自配置文件。任何人都可以帮助我吗?

服务项目的配置:

>     <?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>
>     <bindings>
>       <basicHttpBinding>
>         <binding name="BasicHttpBinding_IService1" />
>       </basicHttpBinding>
>     </bindings>
>     <client>
>       <endpoint address="http://localhost:8733/Design_Time_Addresses/TOPIAM_WCFLibrary/Service1/"
>         binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
>         contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
>     </client>
>     <behaviors>
>       <serviceBehaviors>
>         <behavior>
>           <!-- To avoid disclosing metadata information, 
>           set the value below to false 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>

WCF 项目的配置

>     <?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="TOPIAM_WCFLibrary.Service1">
>         <host>
>           <baseAddresses>
>             <add baseAddress = "http://localhost:8733/Design_Time_Addresses/TOPIAM_WCFLibrary/Service1/"
> />
>           </baseAddresses>
>         </host>
>         <!-- Service Endpoints -->
>         <!-- Unless fully qualified, address is relative to base address supplied above -->
>         <endpoint address="" binding="basicHttpBinding" contract="TOPIAM_WCFLibrary.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 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>

任何人都可以指出我错在哪里?

4

1 回答 1

0

您应该将带有服务设置的配置文件放入启动的 WinForms 应用程序项目中。

于 2013-08-01T11:35:37.393 回答