Preview 5 configuration help

Topics: Web Api
Oct 20, 2011 at 8:11 AM
Edited Oct 20, 2011 at 8:12 AM

Hi guys,

I'm trying to move from preview 4 to 5 and I am having problems, could you evaluate the following code for me:

----------------------------------

 

            WebApiConfiguration wac = new WebApiConfiguration
            {
                EnableTestClient = true,
                EnableHelpPage = true,

                RequestHandlers = (requestHandlers, serviceEndpoint, operationDescriptions) => 
                {
                    requestHandlers.Clear();
                    requestHandlers.Add(new SecurityOperationHandler());
                },

                ResponseHandlers = (responseHandlers, serviceEndpoint, operationDescriptions) =>
                {
                    responseHandlers.Clear();
                },

                ErrorHandlers = (errorHandlers, serviceEndpoint, operationDescriptions) =>
                {
                    errorHandlers.Clear();
                    errorHandlers.Add(new GlobalErrorHandler());
                }
                
            };

            // Ignore if the uri ends with a slash ('/').
            wac.TrailingSlashMode = TrailingSlashMode.Ignore;
            wac.Formatters.XmlFormatter.UseDataContractSerializer = false;
            
            wac.Formatters.Clear();
            wac.Formatters.Add(new ADPFormUrlEncodedFormatter());
            wac.Formatters.Add(new ADPJSONFormatter());
            wac.Formatters.Add(new ADPXmlFormatter());
            wac.Formatters.Add(new ADPImageFormatter());

            wac.MessageHandlers.Add(typeof(LoggingHandler));
            wac.MessageHandlers.Add(typeof(SecurityHandler));
            wac.MessageHandlers.Add(typeof(UriExtensionHandler));

            wac.MaxReceivedMessageSize = 1024 * 1024 * 10;  // Allow files up to 10MB.
            
            SetMappings();
            AddToRouteTable<ADP.Perman.WebServices.REST.EmployeeStoreContext.Service>("EmployeeStore");
            AddToRouteTable<ADP.Perman.WebServices.REST.CustomerStoreContext.Service>("CustomerStore");

 

------------------------------------

Note the formatters. We are using our own formatters to have maximum control over serialization and de-serialization. However the initialization throws an exception:

 

Unable to generate a temporary class (result=1).
error CS0200: Property or indexer 'ADP.WebServices.REST.Serializable.DatabaseListProxy.Databases' cannot be assigned to -- it is read only
error CS0200: Property or indexer 'ADP.WebServices.REST.Serializable.DatabaseListProxy.Databases' cannot be assigned to -- it is read only
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Unable to generate a temporary class (result=1).
error CS0200: Property or indexer 'ADP.WebServices.REST.Serializable.DatabaseListProxy.Databases' cannot be assigned to -- it is read only
error CS0200: Property or indexer 'ADP.WebServices.REST.Serializable.DatabaseListProxy.Databases' cannot be assigned to -- it is read only


Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: Unable to generate a temporary class (result=1).
error CS0200: Property or indexer 'ADP.WebServices.REST.Serializable.DatabaseListProxy.Databases' cannot be assigned to -- it is read only
error CS0200: Property or indexer 'ADP.WebServices.REST.Serializable.DatabaseListProxy.Databases' cannot be assigned to -- it is read only
]
   System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence) +1024
   System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies) +1997
   System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace) +149
   System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace) +549
   System.Xml.Serialization.XmlSerializer..ctor(Type type) +6
   Microsoft.ApplicationServer.Http.Description.HttpOperationHandlerFactory.SetSerializerForXmlFormatter(HttpOperationDescription operation, Type type, MediaTypeFormatterCollection formatters) +477
   Microsoft.ApplicationServer.Http.Description.HttpOperationHandlerFactory.SetXmlAndJsonSerializers(HttpOperationDescription operation, HttpParameter httpParameter, MediaTypeFormatterCollection formatters) +137
   Microsoft.ApplicationServer.Http.Description.HttpOperationHandlerFactory.OnCreateResponseHandlers(ServiceEndpoint endpoint, HttpOperationDescription operation) +823
   Microsoft.ApplicationServer.Http.Configuration.HttpConfigurationOperationHandlerFactory.OnCreateResponseHandlers(ServiceEndpoint endpoint, HttpOperationDescription operation) +45
   Microsoft.ApplicationServer.Http.Description.HttpOperationHandlerFactory.CreateResponseHandlers(ServiceEndpoint endpoint, HttpOperationDescription operation) +155
   Microsoft.ApplicationServer.Http.Description.HttpBehavior.OnGetMessageFormatter(ServiceEndpoint endpoint, HttpOperationDescription operation) +117
   Microsoft.ApplicationServer.Http.Description.HttpBehavior.ApplyMessageFormatters(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher, List`1 httpOperations, Boolean isSystemOperation) +657
   Microsoft.ApplicationServer.Http.Description.HttpBehavior.OnApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) +2142
   Microsoft.ApplicationServer.Http.Configuration.HttpConfigurationBehavior.OnApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) +40
   Microsoft.ApplicationServer.Http.Description.HttpBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) +150
   System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +4275
   System.ServiceModel.ServiceHostBase.InitializeRuntime() +60
   System.ServiceModel.ServiceHostBase.OnBeginOpen() +27
   System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +50
   System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +318
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +206
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +651

[ServiceActivationException: The service '/services/SecurityStore' cannot be activated due to an exception during compilation.  The exception message is: Unable to generate a temporary class (result=1).
error CS0200: Property or indexer 'ADP.Perman.WebServices.REST.Serializable.DatabaseListProxy.Databases' cannot be assigned to -- it is read only
error CS0200: Property or indexer 'ADP.Perman.WebServices.REST.Serializable.DatabaseListProxy.Databases' cannot be assigned to -- it is read only
.]
   System.Runtime.AsyncResult.End(IAsyncResult result) +688590
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
   System.ServiceModel.Activation.AspNetRouteServiceHttpHandler.EndProcessRequest(IAsyncResult result) +6
   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +96

 

Any help would be greatly appreciated!

Gerben.

Oct 20, 2011 at 10:11 AM

Got it.

Apparantly, this is required:

RouteTable.Routes.SetDefaultHttpConfiguration(wac);

What that has to do with the SetXmlAndJsonSerializers beats me.