I am trying to implement a HTTP cache invalidation with API Platform and AWS CloudFront and as I can read in API Platform documentation:
Support for reverse proxies other than Varnish can easily be added by implementing the ApiPlatform\Core\HttpCache\PurgerInterface
I have coded an implementation but now I can not make the built-in cache invalidation system -should be the event listener ApiPlatform\Core\Bridge\Doctrine\EventListener\PurgeHttpCacheListener- it just keep injecting the ApiPlatform\Core\HttpCache\VarnishPurger instead.
What I did basically, in config/services.yml -having autowire enabled:
ApiPlatform\Core\HttpCache\PurgerInterface: '#App\ApiPlatform\HttpCache\CloudFrontPurger'
ApiPlatform\Core\Bridge\Doctrine\EventListener\PurgeHttpCacheListener:
arguments:
$purger: '#App\ApiPlatform\HttpCache\CloudFrontPurger'
Any thoughts?
Alright! Found the issue. PurgeHttpCacheListener is using a service ID so it cannot be autowired according to the Symfony docs.
From vendor/api-platform/core/src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm_http_cache_purger.xml:
<service id="api_platform.doctrine.listener.http_cache.purge" class="ApiPlatform\Core\Bridge\Doctrine\EventListener\PurgeHttpCacheListener">
<argument type="service" id="api_platform.http_cache.purger" />
<argument type="service" id="api_platform.iri_converter" />
<argument type="service" id="api_platform.resource_class_resolver" />
<tag name="doctrine.event_listener" event="preUpdate" />
<tag name="doctrine.event_listener" event="onFlush" />
<tag name="doctrine.event_listener" event="postFlush" />
</service>
The solution is simple. In your service.yml just inject it using its service ID as follow:
api_platform.http_cache.purger:
class: App\ApiPlatform\HttpCache\CloudFrontPurger
Related
I am working on Azure Service Fabric Reliable Actor implementation. Any idea/link on where can I store the Configuration value (e.g. DB connection string) and how to access that in code.
A Service Fabric application consists of the code package, a config package, and the data (https://azure.microsoft.com/en-gb/documentation/articles/service-fabric-application-model/).
You can use the config package to store and retrieve any kind of key-value pairs you need e.g. a connection string. Have a look at this article https://azure.microsoft.com/en-us/documentation/articles/service-fabric-manage-multiple-environment-app-configuration/ for more information.
You can add multiple ApplicationParameters file. Just copy and paste the same from Cloud.Xml and use for multiple environment configurations.
Steps to Make necessary changes
The values given in the Settings.xml need to be overridden in the ApplicationManifest.xml when it imports the ServiceManifest.xml .Below is the code supporting the overriding changes add them in the ApplicationManifest.xml.
a) Add the Parameter Default value first
<Parameters>
<Parameter Name="StatelessService1_InstanceCount" DefaultValue="-1" />
<!-- Default Value is set to Point to Dev Database -->
<Parameter Name="DatabaseString"DefaultValue="Server=someserver.database.windows.net\;Database=DbDev;user id=[userid];password=[Password];Trusted_Connection=false;" />
</Parameters>
b) Then override it in the ServiceManifestImport
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="StatelessServicePkg"
ServiceManifestVersion="1.0.0" />
<ConfigOverrides>
<ConfigOverride Name="Config">
<Settings>
<Section Name="DatabaseConnections">
<Parameter Name="DbString" Value="[DatabaseString]" />
</Section>
</Settings>
</ConfigOverride>
</ConfigOverrides>
</ServiceManifestImport>
The above code change will override the following code in settings.xml
<Section Name="DatabaseConnections">
<Parameter Name="DbString" Value="Server=someserver.database.windows.net\;Database=DbDev;user id=[userid];password=[Password];Trusted_Connection=false;" />
</Section>
Overall when the application is deployed the values in the ApplicationParameter DevParam.xml or QaParam.xml or ProdParam.xml will overtake all the setting values.
<Parameters>
<Parameter Name="StatelessService1_InstanceCount" Value="-1" />
<Parameter Name="DatabaseString" Value="Server=someserverqa.database.windows.net\;Database=DbQA;user id=[userid];password=[Password];Trusted_Connection=false;" />
</Parameters>
In addition to the above info, it is important to know the order in which ASF overrides application setting:
Service Fabric will always choose from the application parameter file
first (if specified), then the application manifest, and finally the
configuration package (source)
For more info:
http://www.binaryradix.com/2016/10/reading-from-configuration-within-azure.html
A weird thing happened to my project. I have an Azure WCF project which basically consists of the WebRole and the Azure project. Azure Project contains ServiceDefinition.csdef which in turn contains stuff like endpoint information.
I was playing around in my WebRole and manually set an endpoint there. However, my original issue, due to a stupid user error, did not require this. After I removed the endpoint devinition from web.config, my webrole still gets bound to port 6627 instead of the two endpoints described in my Azure project (80 & 8080). I can't find that port being mentioned anywhere so I'm guessing it is the default.
Here's the part of the web.config that I edited (the removed part is in comments). How do I revert back to getting the configuration from the Azure project?
<system.serviceModel>
<!-- services>
<service name="MyWebRole.MyService" behaviorConfiguration="MyWebRole.BasicUserInformationBehavior">
<endpoint address="" binding="mexHttpBinding" contract="MyWebRole.IMyService"/>
</service>
</services -->
<extensions>
<behaviorExtensions>
<add name="userInformationProcessor" type="MyWebRole.BasicUserInformationBehaviorExtensionElement, MyWebRole, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
<bindings />
<client />
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<userInformationProcessor />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
[Edit] More information on the subject! The problem is related to compute emulator no longer starting at all! I don't know why the service works then, but I guess it's running it IIS alone.
I think the solution as mentioned in the comment is that you have to set up the Windows Azure project as the startup project not the webrole.
How do I configure Azure Cache in web roles to use my custom IDataCacheObjectSerializer class? In case you are wondering why I want to use a custom serializer: I want to use the compact text based style JSON(.net) serialization combined with compression. In my .config files I can enable compression:
<dataCacheClient name="default" isCompressionEnabled="true"/>
But how / where do I tell Azure Cache (preview) to use my custom IDataCacheObjectSerializer class that uses JSON serialization?
Jagan Peri has a relevant blog post.
From the post:
<dataCacheClients>
<tracing sinkType="DiagnosticSink" traceLevel="Verbose" />
<!-- This is the default config which is used for all Named Caches
This can be overriden by specifying other dataCacheClient sections with name being the NamedCache name -->
<dataCacheClient name="default" useLegacyProtocol="false">
<autoDiscover isEnabled="true" identifier="WorkerRole1" />
<!--<localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" />-->
<serializationProperties serializer="CustomSerializer" customSerializerType="Your.Fully.Qualified.Path.To.IDataCacheObjectSerializer,WorkerRole1" />
</dataCacheClient>
</dataCacheClients>
we currently set WCF RIA Services Link from the Silverlight client, I currently looking for the config file to changes some wcf settings. Is that possible?
You need to add appropriate settings and behaviors to your service endpoints.
Here is an example of an endpoint behavior that increases maxItemsInObjectGraph:
<endpointBehaviors>
<behavior name="ClientMaxItemsInObjectGraphBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
It is referenced using behaviorConfiguration= in an endpoint like this:
<endpoint contract="AssemblyName.IContactName"
address="http://localhost:50101/MyService.svc"
behaviorConfiguration="ClientMaxItemsInObjectGraphBehavior"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_Default"
name="MyServiceEndpoint">
</endpoint>
Most of the other settings relate to the service binding which was referenced by bindingConfiguration= e.g.:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_Default"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
<readerQuotas maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="16384"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
</binding>
It is probably easier to study the matching classes and properties than the config files. Configs get messy very fast, but they just reflect a hierarchy of properties at run-time so working backwards from the class documentation may help you understand where the various settings go.
I had an application that was running on IIS 6. All requests went through aspnet_isapi.dll. This was achieved via a wildcard application mapping (which did not verify the file existed).
I have copied said application to a machine running IIS7, and would like to get it working again.
In the application, any request with an extension of .aspx (or .ashx) are handled in the normal way. Other requests with different extensions (such as .html and .xml) are handled by a custom http module. Some requests have no extension, and are dynamically redirect to a file with an extension (e.g. visiting …/item/1 might redirect to …/item/1.html or …/item/1.xml, depending on values in the accept header).
The new location probably does not exist, but a response is generated dynamically.
Currently, the application pool is in “classic” mode, and is using .NET v4.0 (it was previously using .NET 3.5, but that doesn’t seem to be related to the problem). The custom http module is set only in the web.config.
The redirect (from …/item/1 to …/item/1.html) seems to work, which suggests that extension less requests are indeed being processed by the application (that redirect is written in the application itself). I think that means that the custom module is working.
Requests with extensions (.html, .xml etc) are failing however. The error I get is:
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Module: IIS Web Core
Notification: MapRequestHandler
Handler: StaticFile
Error Code: 0x80070002
I have tried:
Adding a wildcard script mapping that mapped * to aspnet_isapi.dll
Tried adding a specific mapping for *.html to aspnet_isapi.dll
These still result in the same error message, and still seem to go to the handler "StaticFile".
I tried modifying "StaticFile" so that it uses the aspnet_isapi.dll executable, and this results in a new error:
HTTP Error 404.4 - Not Found
The resource you are looking for does not have a handler associated with it.
Handler: Not yet determined
Any help would be greatly appreciated.
Set application pool in integrated mode and set that all request run all managed modules
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
...
</modules>
...
</system.webServer>
Use this config in service config it worked for me.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfService.Service1">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="secureHttpBinding"
contract="WcfService.IService1"/>
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpsGetEnabled="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>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>