2013-08-01 131 views
1

我有一個Windows服務和一個窗體,我需要它們進行通信。我訪問的每個站點都指向WCF。我試圖先在服務上實現它。像這樣:C# - WCF無法在Windows服務上找到端點

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,字符串configurationName) 在System.ServiceModel.ChannelFactory.ApplyConfiguration(字符串configurationName,配置結構) 在System.ServiceModel.ChannelFactory.ApplyConfiguration(字符串configurationName) 在系統.ServiceModel.ChannelFactory.InitializeEndpoint(字符串configurationName,地址的EndpointAddress) 在System.ServiceModel.ChannelFactory 1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) at System.ServiceModel.ConfigurationEndpointTrait 1.CreateSimplexFactory() 在System.ServiceModel.Config ...

我擡頭一看幾個小時,但仍沒有線索我應該如何得到配置文件的權利。

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項目的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="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> 

任何人都可以指出,我把它錯了嗎?

回答

0

你應該把你的配置文件的服務設置放入啓動WinForms應用程序項目中。

相關問題