WebAPI找不到WCF端点元素 [英] WebAPI cannot find WCF endpoint element

查看:61
本文介绍了WebAPI找不到WCF端点元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过.Net 4.5 C#MVC4 WebAPI(RCWindsExtSvc)使用有效的C#WCF服务(RCWindsSvc)。从WebAPI调用WCF服务时收到以下运行时错误:



'找不到名为'RCWindsSvcEndpoint'和合同'RCWindsSvc的端点元素。 ServiceModel客户端配置部分中的IService1'。

这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此名称匹配的端点元素。'



WCF服务中web.config的system.serviceModel是:



 <   system.serviceModel  >  
< 服务 >
< service name = RCWindsSvc.Service1 behaviorConfiguration = RCWin dsSvc.Service1Behavior >
< endpoint address = http:// localhost:15021 / RCWinds.svc
binding = webHttpBinding
合同 = RCWindsSvc.IService1
behaviorConfiguration = ServiceAspNetAjaxBehavior
名称 = RCWindsSvcEndpoint / >
<! - behaviorConfiguration =WebBehaviour/> - >
< / service >
< / services >
< 行为 >
< serviceBehaviors >
< 行为 名称 = RCWindsSvc.Service1Behavior >
<! - 为避免泄露元数据信息,请将以下值设置为false并在部署之前删除上面的元数据端点 - >
< serviceMetadata httpGetEnabled = true < span class =code-keyword> /
>
<! - 要接收故障中的异常详细信息以进行调试,请将以下值设置为true。在部署之前设置为false以避免泄露异常信息 - >
< serviceDebug includeExceptionDetailInFaults = false / >
< / behavior < span class =code-keyword>>
< / serviceBehaviors >
< endpointBehaviors >
<! - < behavior name =webBehaviour>
< webHttp />
< / behavior>
- >

< ; 行为 名称 < span class =code-keyword> = ServiceAspNetAjaxBehavior >
< enableWebScript / >
< / behavior >
< / endpointBehaviors >
< / behavior > ;
< serviceHostingEnvironment aspNetCompatibilityEnabled = true multipleSiteBindingsEnabled = false / >
< / system.serviceModel >





我在WebAPI代码中使用ConfigurationChannelFactory来检索WCF配置数据,以下是WebAPI控制器的代码:



  public   String  [] GetStationName s()
{
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = web.config;
配置newConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap,ConfigurationUserLevel.None);

ConfigurationChannelFactory< RCWindsSvc.IService1> factory1 = new
ConfigurationChannelFactory< RCWindsSvc.IService1>( RCWindsSvcEndpoint,newConfiguration, new EndpointAddress( HTTP://本地主机:15021 / RcWinds.svc));
RCWindsSvc.IService1 client1 = factory1.CreateChannel();

IEnumerable< string> stationNames = client1.GetStationNames();
return stationNames.ToArray();

}





这似乎是一个很常见的问题我已探索过一个数字建议的解决方案无济于事。非常感谢任何帮助。

解决方案

谢谢Kumarbs。我仍然收到以下配置和代码的错误消息:



我的新 WebAPI配置是:



 <   system.servicemodel  >  
< client >
< endpoint name = RCWindsSvc.Service1 >
contract =RCWindsSvc.IService1
binding =webHttpBinding
address =http:// localhost:15021 / RCWinds.svc>
< / endpoint >
< / client > < / system.servicemodel >





代码段:



  public   class  RCWindsExtSvcController:ApiController 
{

public String [] GetStationNames()
{
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = web.config;
配置newConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap,ConfigurationUserLevel.None);

ConfigurationChannelFactory< rcwindssvc.iservice1> factory1 = new
ConfigurationChannelFactory< rcwindssvc.iservice1>( RCWindsSvc.Service1,newConfiguration, new EndpointAddress( HTTP://本地主机:15021 / RCWinds.svc));
RCWindsSvc.IService1 client1 = factory1.CreateChannel();

IEnumerable< string> stationNames = client1.GetStationNames();
return stationNames.ToArray();
}
} < / string > < / rcwindssvc.iservice1 > < / rcwindssvc.iservice1 >





谢谢。


我能够解决通过做两件事:1)删除ConfigurationChannelFactory代码和2)我使用服务配置编辑器实用程序(SvcConfigEditor.exe)在WebApi端正确构建客户端部分。完成后,我能够超越错误。我收到另一个不同的错误,我将在新帖子中发布。

感谢大家。 DAFuller

I am attempting to consume a working C# WCF service (RCWindsSvc) via a .Net 4.5 C# MVC4 WebAPI (RCWindsExtSvc). I am receiving the following run-time error when calling the WCF service from the WebAPI:

'Could not find endpoint element with name 'RCWindsSvcEndpoint' and contract 'RCWindsSvc.IService1' in the ServiceModel client configuration section.
This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.'

The system.serviceModel from the web.config in the WCF Service is:

 <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>



I am using ConfigurationChannelFactory in the WebAPI code to retrieve the WCF configuration data, and the following is the code from the WebAPI Controller:

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();

           }



This seems to be a somwhat common issue and I have explored a number of suggested solutions to no avail. Any assistance with this is greatly appreciated.

解决方案

Thank you, Kumarbs. I am still receiving the error message with the following config and code:

My new WebAPI config is:

<system.servicemodel>
   <client>
     <endpoint name="RCWindsSvc.Service1">
               contract="RCWindsSvc.IService1"
               binding="webHttpBinding"
               address="http://localhost:15021/RCWinds.svc">
     </endpoint>
   </client></system.servicemodel>



Code snippet:

public class RCWindsExtSvcController : ApiController
    {

        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>("RCWindsSvc.Service1", newConfiguration, new EndpointAddress("http://localhost:15021/RCWinds.svc"));
                RCWindsSvc.IService1 client1 = factory1.CreateChannel();

                IEnumerable<string> stationNames = client1.GetStationNames();
                return stationNames.ToArray();
            }
    }</string></rcwindssvc.iservice1></rcwindssvc.iservice1>



Thank you.


I was able to resolve this by by doing two things: 1) remove the ConfigurationChannelFactory code and 2)I use the Service Configuration Editor utility (SvcConfigEditor.exe) to properly build the client section on the WebApi side. When complete, I was able to move past the error. I am receiving another, different error which I will post in a new thread.
Thanks to everyone. DAFuller


这篇关于WebAPI找不到WCF端点元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆