我有一个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) at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName,configuration) at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName) at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName,EndpointAddress address) at System.ServiceModel.ChannelFactory
1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) at System.ServiceModel.ConfigurationEndpointTrait1.CreateSimplexFactory() at 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项目的配置
> <?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>有人能指出我哪里错了吗?
发布于 2013-08-01 11:35:37
您应该将带有服务设置的配置文件放入启动WinForms应用程序项目。
https://stackoverflow.com/questions/17992760
复制相似问题