C# WebAPI找不到WCF端点元素
我正试图通过.Net 4.5 C MVC4 WebAPI RCWindTextSvc使用一个工作的C WCF服务RCWindSvc。从WebAPI调用WCF服务时,我收到以下运行时错误: '在ServiceModel客户端配置节中找不到名为'RCWindsCsCEndpoint'且合同为RCWindsCsvc.IService1'的终结点元素。 这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此名称匹配的端点元素。” WCF服务中web.config中的system.serviceModel是:C# WebAPI找不到WCF端点元素,c#,wcf,asp.net-mvc-4,asp.net-web-api,endpoint,C#,Wcf,Asp.net Mvc 4,Asp.net Web Api,Endpoint,我正试图通过.Net 4.5 C MVC4 WebAPI RCWindTextSvc使用一个工作的C WCF服务RCWindSvc。从WebAPI调用WCF服务时,我收到以下运行时错误: '在ServiceModel客户端配置节中找不到名为'RCWindsCsCEndpoint'且合同为RCWindsCsvc.IService1'的终结点元素。 这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此名称匹配的端点元素。” WCF服务中web.config中的system.servic
<system.serviceModel>
<services>
<service name="RCWindsSvc.Service1" behaviorConfiguration="RCWindsSvc.Service1Behavior">
<endpoint address="http://localhost:15021/RCWinds.svc"
binding="webHttpBinding"
contract="RCWindsSvc.IService1"
behaviorConfiguration="ServiceAspNetAjaxBehavior"
name="RCWindsSvcEndpoint"/>
<!-- behaviorConfiguration="WebBehaviour" /> -->
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="RCWindsSvc.Service1Behavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above 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>
<endpointBehaviors>
<!-- <behavior name="webBehaviour">
<webHttp/>
</behavior>-->
<behavior name="ServiceAspNetAjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
</system.serviceModel>
我在WebAPI代码中使用ConfigurationChannelFactory检索WCF配置数据,以下是来自WebAPI控制器的代码:
public String[] GetStationNames()
{
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = "web.config";
Configuration newConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
ConfigurationChannelFactory<RCWindsSvc.IService1> factory1 = new
ConfigurationChannelFactory<RCWindsSvc.IService1>("RCWindsSvcEndpoint", newConfiguration, new EndpointAddress("http://localhost:15021/RcWinds.svc"));
RCWindsSvc.IService1 client1 = factory1.CreateChannel();
IEnumerable<string> stationNames = client1.GetStationNames();
return stationNames.ToArray();
}
这似乎是一个共同的问题,我已经探讨了一些建议的解决方案,但都没有结果。非常感谢您提供的任何帮助。您的配置文件中缺少一个客户端部分
<system.serviceModel>
<bindings>
...
</bindings>
<client>
<endpoint address="http://localhost:15021/RCWinds.svc"
binding="webHttpBinding"
contract="RCWindsSvc.IService1" name="RCWindsSvcEndpoint" />
</client>
</system.serviceModel>
首先,当您浏览到Thiago时,是否可以显示wsdl?Thiago-是的,wsdl显示。Thiago,我将客户机部分添加到WCF配置文件中,但仍然收到错误。您是否同时添加了.config文件WCF/webapi?不,只是WCF服务。我的印象是ConfigurationChannelFactory将使新的WCF配置可用于WebAPI。为什么您不能仅使用WebRequest调用WCF服务。通过您的WebAPI创建?我不熟悉该过程-这是建议的方向吗?