This is how we created the wsdl exporter:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 since 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. What's next? get this blog rss updates or register for mail updates!
1 comments:
It’s so refreshing to find articles like the ones you post on your site. Very informative reading. I will keep you bookmarked. Thanks!
Post a Comment