How to create IntelliSense compatible documentation for generated WCF proxy classes?
I am trying to add IntelliSense and SandCastle compatible documentation to my WCF proxy classes that were generated via svcutil. Is there any way to do this without directly editing the genera开发者_运维百科ted code (as it would be lost if it is ever regenerated)?
In the WCFExtras project you can find the functionality you are looking for; a WSDL exporter and importer that takes XML code documentation and embeds it in the WSDL + pulls it out and adds it as XML doc again on the generated client-side proxy.
WCFExtras can be found here: http://wcfextras.codeplex.com/ (or as a Nuget package).
--larsw
A limited solution may be to create documentation only partial classes to mirror the classes generated by SvcUtil. Since the SvcUtil classes are created as partial classes, you can take advantage of this for documenting the class but this probably won't work for the methods or properties. IntelliSense will display the comments. I believe SandCastle will also merge the comments but haven't tried it. It could be a pain to keep these classes in sync with the service changes if you want to go this route.
Here is what the documentation class would look like:
/// <summary>
/// This is a comment
/// </summary>
public partial class YourSvcUtilGenerateClientClass { }
I think you can override the way these classes are generated with a template. Here is a link to an article talking. They are focusing on silverlight but i think the code context is still applicable.
http://www.silverlightshow.net/items/ADO.NET-Data-Services-Advanced-Topics-Custom-proxy-based-on-T4-templates.aspx
Personally, I don't ever use the generated WCF proxy classes. It's too easy to roll your own proxy class. This is all it takes (the methods can be added for you by Visual Studio when you add your ServiceContract interface on your proxy class):
using System.ServiceModel;
namespace My.Namespace
{
public class MyServiceContractProxy : ClientBase<IMyServiceContract>, IMyServiceContract
{
public MyServiceContractProxy() { }
public MyServiceContractProxy(string endpointName) : base(endpointName) { }
#region IMyServiceContract Members
public int AddValues(int val1, int val2)
{
return Channel.AddValues(val1, val2);
}
#endregion
}
}
If your ServiceContract changes, it will throw a compile error because your proxy will no longer match the interface, but it's typically not more than 10-second edit to your proxy class.
Since the XML comments route won't meet your needs then the Document! X 2011 product would be a choice. It isn't free but it will do what you need.
精彩评论