Kindly let me know 开发者_开发技巧how to create WSDL for a WCF service programmatically.
You can use the MetadataSet and WsdlImporter classes to do this if you have a mex endpoint exposed for whatever service it is that you are trying to generate WSDL against.
If the service you are trying to generate WSDL for is compiled code, you should be able to make use of svcutil for that.
You can do the following:
ContractDescription cd = ContractDescription.GetContract(typeof(IContract));
System.ServiceModel.Description.WsdlExporter wexp = new System.ServiceModel.Description.WsdlExporter();
wexp.ExportContract(cd);
MetadataSet mds = wexp.GetGeneratedMetadata();
mds.WriteTo(new XmlTextWriter(@".\IContract.wsdl", Encoding.UTF8));
Also, here is good article about it: http://mleder.blogspot.com/2008/05/creating-wsdl-using-c.html
I don't think this is possible, other than programmatically using svcutil.exe to achieve the task.
better late than never, but I think you're after the IWsdlExportExtension behaviour, which allows you to modify the WSDL generated by WCF when the service is hosted - here is a good blog post on how to get started when implementing this interface.
精彩评论