windows应用程序调用WCF时出现错误
本文关键字:错误 WCF 应用程序 调用 windows | 更新日期: 2023-09-27 18:09:32
我开发了窗口应用程序,我在特定的时间间隔调用WCF,但是通过WCF插入数据到数据库中没有错误,但在日志条目中,我得到了一个关于WCF端点的错误,如下所示
2011-22-09 10:16>>错误:没有端点侦听myserviceUrl(.svc)可以接受消息。这通常是由错误的地址或SOAP操作引起的。参见InnerException, if
应用程序。配置文件如下所示,我猜可能错误应该在下面的配置
<client>
<endpoint address="myserviceUrl(.svc)"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF"
contract="Dashboard2WCFData.IApicaAzureMonitorAgentReceiverWCF"
name="BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF" />
</client>
下面是我的(WCF)服务的配置。
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</configSections>
<dataConfiguration defaultDatabase="Connectionstr"/>
<connectionStrings>
<add name="Connectionstr" connectionString="myconnectionstring"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
请帮我解决一下这个问题。
谢谢。
您需要确保在服务端配置端点,而不仅仅是在您的客户端。换句话说,如果客户端使用myserviceUrl(.svc)
,则需要在服务的配置文件中指定该地址。
根据你得到的错误信息,在服务的配置文件中试试这个:
<endpoint address="myserviceUrl(.svc)"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF"
contract="Dashboard2WCFData.IApicaAzureMonitorAgentReceiverWCF"
name="BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF" />
注意,你需要确保你的服务有适当的绑定部分,名为"BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF"。
如果你需要一个更全面的例子,发布你的服务的配置文件,我们会帮助你。
添加一个端点部分,如果您将任何值设置为默认值以外的其他值,则添加一个绑定部分:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="myServiceName">
<endpoint address="myserviceUrl(.svc)"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF"
contract="Dashboard2WCFData.IApicaAzureMonitorAgentReceiverWCF"
name="BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF"/>
<endpoint name="mexHttpBinding"
contract="IMetadataExchange"
binding="mexHttpBinding"
address="mex" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF" />
</basicHttpBinding>
</bindings>
在<binding name=""
部分中,您将为绑定设置值。如果你不这样做(并且没有在端点的bindingConfiguration属性中指定该部分),WCF将使用basicHttpBinding的默认值。
注意:对于WCF 4.0和更高版本,实际上不需要指定端点(或者如果托管在IIS下创建.svc文件),因为WCF将根据服务的URI提供默认端点。有关此功能和4.0中其他新功能的详细信息,请参阅开发人员Windows Communication Foundation 4介绍。
需要在address属性中指定整个虚拟路径例如http://localhost/yousite/myservice.svc