DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Data Engineering
  3. Data
  4. How To Fix the WCF Cache of Dynamic WSDLs

How To Fix the WCF Cache of Dynamic WSDLs

Yaron Naveh user avatar by
Yaron Naveh
·
May. 05, 12 · Interview
Like (0)
Save
Tweet
Share
4.02K Views

Join the DZone community and get the full member experience.

Join For Free

One of the least used WCF extension points is IWsdlExportExtension. This extension allows to customize the WSDL document which WCF emits. Since you rarely want to do that, this extension is not commonly used. When it is already used it is usually in the context of flattening the WSDL. A different use case I have recently seen is to push dynamic content into the WSDL. More specifically a user was trying to generate XSD schemas from a live database table and to put it to the WSDL so clients would always get the latest schema. The WCF service itself was treating the request as XML anyway so it did not care for such changes. The requirement was for the wsdl to reflect the latest DB changes at any time. Our problem was that once the WSDL was generated for the first time it would not be regenerated. This resulted in a stale schema.

This is how we created the WSDL exporter:

static void Main(string[] args)
{
  using (ServiceHost host = new ServiceHost(typeof(Service)))
  {
    host.Description.Behaviors.Add(new ServiceMetadataBehavior() {
                        HttpGetEnabled = true,
                        HttpGetUrl = new System.Uri("http://localhost:7171/")});
    var ep = host.AddServiceEndpoint("IService", new BasicHttpBinding(),
                        "http://localhost:7171/");
    ep.Behaviors.Add(new MyWsdlExporter());
    host.Open();
                                        
    Console.WriteLine("\nPress enter to close service...\n");
    Console.ReadLine();
  }
}

class MyWsdlExporter : IWsdlExportExtension, IEndpointBehavior
{
   public void ExportEndpoint(WsdlExporter exporter,
                              WsdlEndpointConversionContext context)
   {
       context.WsdlPort.Documentation = "crearted on " + DateTime.Now.ToString();
   }
}
When we run this service and open the WSDL we get this:
<wsdl:port name="BasicHttpBinding_IService" binding="tns:BasicHttpBinding_IService">
<wsdl:documentation>crearted on 05/05/2012 21:08:13</wsdl:documentation>
When we refresh the WSDL after a few seconds we still get this:
<wsdl:port name="BasicHttpBinding_IService" binding="tns:BasicHttpBinding_IService">
<wsdl:documentation>crearted on 05/05/2012 21:08:13</wsdl:documentation>
This is not a browser or proxy cache. WCF does not recreate the WSDL - which can also be seen by putting a breakpoint (which is only called once) on the exporter.

This behavior makes sense when you consider the case where there is no importer extension - then the wsdl is generated based on the data contract assembly, and as long as that assembly does not change the wsdl will not also. However we have chose to put dynamic logic in ExportEndpoint method so that default behavior did not work well for us.

One way to fix that is to use a message inspector to update the wsdl before it is sent to the client. In this case IWsdlExportExtension is not required at all. This approach is described here.

An alternative could be to build a WCF REST endpoint in the same service to act as a proxy to the real WSDL.
Windows Communication Foundation Cache (computing)

Published at DZone with permission of Yaron Naveh, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 5 Software Developer Competencies: How To Recognize a Good Programmer
  • 5 Best Python Testing Frameworks
  • How Chat GPT-3 Changed the Life of Young DevOps Engineers
  • The Power of Docker Images: A Comprehensive Guide to Building From Scratch

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: