在运行时找不到DynamicProxy即服务

时间:2014-04-02 15:53:44

标签: wcf castle-dynamicproxy

我正在尝试开发一个WCF服务,用作来自提供商的已定义Web服务的代理。

以下是我为实现这一目标而采取的步骤:

  1. 创建WCF服务应用程序
  2. 添加了对提供者Web服务的服务引用
  3. 在项目中添加了Global.asax
  4. 通过NuGet向项目添加了Castle.Core(v3.2)引用。
  5. 在Global.asax
  6. 中添加了一些代码

    以下是我Global.asax

    中的代码
    /// <summary>
    /// Contiene eventos globales ejecutados 
    /// </summary>
    public class Global : HttpApplication
    {
    
        private static readonly ProxyGenerator generator = new ProxyGenerator();
    
        private static List<object> proxies = new List<object>();
    
        /// <summary>
        /// Evento que se ejecuta cuando se inicializa la aplicacion
        /// </summary>
        /// <param name="sender">Objeto que origna el evento</param>
        /// <param name="e">Argumentos del evento</param>
        protected void Application_Start(object sender, EventArgs e)
        {
            ConfigurarServicios();
        }
    
        /// <summary>
        /// Busca los servicios registrados en el proyecto
        /// </summary>
        /// <returns>Coleccion de servicios registrados y que extienden
        /// la clase ServiceBase</returns>
        private static IEnumerable<Type> BuscarServicios()
        {
            ConfigurarProxies();
    
            var list = new List<Type>();
    
            foreach (var proxy in proxies)
            {
                list.Add(proxy.GetType());
            }
    
            return list;
        }
    
        /// <summary>
        /// Configura los servicios del proyecto para ser accedidos
        /// a traves de REST y SOAP
        /// </summary>
        private static void ConfigurarServicios()
        {
            var soapFactory = new ServiceHostFactory();
    
            var services = BuscarServicios();
            foreach (var serviceType in services)
            {
                string serviceName = "xm";
    
                var soapEndpoint = new ServiceRoute("Servicios/" + serviceName, soapFactory, serviceType);
    
    
                RouteTable.Routes.Add("Servicios/" + serviceName,soapEndpoint);
    
            }
        }
    
        private static void ConfigurarProxies()
        {
            var interceptor = new Interceptor(); 
    
            var proxy1 = generator.CreateInterfaceProxyWithoutTarget(typeof(ExternalServices.XpressMoney.XMSendTxnServicePortType), interceptor);
    
    
            proxies.Add(proxy1);
        }
    }
    

    当我运行项目时,一切正常,但当我尝试访问ServiceRoute / Servicios / xm时,它会显示下一个错误:

    The type 'Castle.Proxies.XMSendTxnServicePortTypeProxy, DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
    

    这就是堆栈:

    [InvalidOperationException: The type 'Castle.Proxies.XMSendTxnServicePortTypeProxy, DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null', provided a the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.]
       System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +59318
       System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +1434
       System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +52
       System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +598
    
    
    [ServiceActivationException: The service '/Servicios/xm' cannot be activated due to an exception during compilation.  The exception message is: The type 'Castle.Proxies.XMSendTxnServicePortTypeProxy, DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found..]
       System.Runtime.AsyncResult.End(IAsyncResult result) +499812
       System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178
       System.ServiceModel.Activation.AspNetRouteServiceHttpHandler.EndProcessRequest(IAsyncResult result) +6
       System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +129
    

    我想当.NET Framework尝试动态实例化DynamicProxy时会出现问题,但我真的不知道。也许Next Lines是一个线索:

    var soapEndpoint = new ServiceRoute("Servicios/" + serviceName, soapFactory, serviceType);
    
    RouteTable.Routes.Add("Servicios/" + serviceName,soapEndpoint);
    

    希望你能帮助我。

0 个答案:

没有答案