WCF服务文档
在程序员和非程序员都会看到的技术产品文档中记录/发布WCF服务信息的最佳方式是什么?还有,出版的最佳工具是什么 这充其量是一个棘手的问题!:-) 您可以将您的WCF服务描述导出到WSDL文件,并使用WCF服务文档,wcf,Wcf,在程序员和非程序员都会看到的技术产品文档中记录/发布WCF服务信息的最佳方式是什么?还有,出版的最佳工具是什么 这充其量是一个棘手的问题!:-) 您可以将您的WCF服务描述导出到WSDL文件,并使用和元素对其进行丰富,然后使用XSLT转换将其转换为可读的HTML文档-但这并不是很好和有用,真的 这里有一个链接显示了如何做到这一点: 一些XML工具还提供了记录WSDL文件的方法—通常也来自那些文档和注释标记—一个示例如下: 下面是一个在线版本(以及可下载的XSLT转换),用于将文档和注释元素从W
和
元素对其进行丰富,然后使用XSLT转换将其转换为可读的HTML文档-但这并不是很好和有用,真的
这里有一个链接显示了如何做到这一点:
一些XML工具还提供了记录WSDL文件的方法—通常也来自那些文档和注释标记—一个示例如下:
下面是一个在线版本(以及可下载的XSLT转换),用于将文档和注释元素从WSDL中转换出来:
我在这里没有最终的答案,但我对这个话题也非常感兴趣
Marc看看这个问题:。当您使用创建WCF REST服务时,会生成一个a。您似乎没有使用REST,但我想我应该提到它,因为这种格式可能适合您 这将使用操作描述公开操作的Atom提要 在这个示例中出现了一些反射:
public Atom10FeedFormatter GetFeed(ContractDescription contractDescription)
{
List<SyndicationItem> items = new List<SyndicationItem>();
foreach (OperationDescription od in contractDescription.Description.Operations)
{
WebGetAttribute get = od.Behaviors.Find<WebGetAttribute>();
WebInvokeAttribute invoke = od.Behaviors.Find<WebInvokeAttribute>();
string method = this.GetMethod(get, invoke);
string requestFormat = null;
if (invoke != null)
{
requestFormat = this.GetRequestFormat(invoke, od);
}
string responseFormat = this.GetResponseFormat(get, invoke, od);
string uriTemplate = this.GetUriTemplate(get, invoke, od);
WebMessageBodyStyle bodyStyle = this.GetBodyStyle(get, invoke);
string requestSchemaLink = null;
string responseSchemaLink = null;
string requestExampleLink = null;
string responseExampleLink = null;
if (bodyStyle == WebMessageBodyStyle.Bare)
{
UriTemplate responseSchemaTemplate = new UriTemplate("help/{operation}/response/schema");
responseSchemaLink = responseSchemaTemplate.BindByPosition(this.BaseUri, new string[] { od.Name }).AbsoluteUri;
UriTemplate responseExampleTemplate = new UriTemplate("help/{operation}/response/example");
responseExampleLink = responseExampleTemplate.BindByPosition(this.BaseUri, new string[] { od.Name }).AbsoluteUri;
if (invoke != null)
{
UriTemplate requestSchemaTemplate = new UriTemplate("help/{operation}/request/schema");
requestSchemaLink = requestSchemaTemplate.BindByPosition(this.BaseUri, new string[] { od.Name }).AbsoluteUri;
UriTemplate requestExampleTemplate = new UriTemplate("help/{operation}/request/example");
requestExampleLink = requestExampleTemplate.BindByPosition(this.BaseUri, new string[] { od.Name }).AbsoluteUri;
}
}
uriTemplate = HttpUtility.HtmlEncode(string.Format("{0}/{1}", this.BaseUri.AbsoluteUri, uriTemplate));
string xhtmlDescription = string.Format("<div xmlns=\"http://www.w3.org/1999/xhtml\"><table border=\"5\"><tr><td>UriTemplate</td><td>{0}</td></tr><tr><td>Method</td><td>{1}</td></tr>", uriTemplate, method);
if (!string.IsNullOrEmpty(requestFormat))
{
xhtmlDescription = xhtmlDescription + string.Format("<tr><td>Request Format</td><td>{0}</td></tr>", requestFormat);
}
if (requestSchemaLink != null)
{
xhtmlDescription = xhtmlDescription + string.Format("<tr><td>Request Schema</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(requestSchemaLink));
}
if (requestExampleLink != null)
{
xhtmlDescription = xhtmlDescription + string.Format("<tr><td>Request Example</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(requestExampleLink));
}
xhtmlDescription = xhtmlDescription + string.Format("<tr><td>Response Format</td><td>{0}</td></tr>", responseFormat);
if (responseSchemaLink != null)
{
xhtmlDescription = xhtmlDescription + string.Format("<tr><td>Response Schema</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(responseSchemaLink));
}
if (responseExampleLink != null)
{
xhtmlDescription = xhtmlDescription + string.Format("<tr><td>Response Example</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(responseExampleLink));
}
WebHelpAttribute help = od.Behaviors.Find<WebHelpAttribute>();
if ((help != null) && !string.IsNullOrEmpty(help.Comment))
{
xhtmlDescription = xhtmlDescription + string.Format("<tr><td>Description</td><td>{0}</td></tr>", help.Comment);
}
xhtmlDescription = xhtmlDescription + "</table></div>";
var item = new SyndicationItem() {
Id = "http://tmpuri.org/" + od.Name,
Content = new TextSyndicationContent(xhtmlDescription, TextSyndicationContentKind.XHtml),
LastUpdatedTime = DateTime.UtcNow,
Title = new TextSyndicationContent(string.Format("{0}: {1}", this.Description.Name, od.Name))
};
items.Add(item);
}
SyndicationFeed feed = new SyndicationFeed()
{
Title = new TextSyndicationContent("Service help page"),
LastUpdatedTime = DateTime.UtcNow,
Items = items
};
WebOperationContext.Current.OutgoingResponse.ContentType = "application/atom+xml";
return feed.GetAtom10Formatter();
}
公共Atom10FeedFormatter GetFeed(合同描述)
{
列表项=新列表();
foreach(contractDescription.Description.Operations中的OperationDescription od)
{
WebGetAttribute get=od.Behaviors.Find();
WebInvokeAttribute invoke=od.Behaviors.Find();
string方法=this.GetMethod(get,invoke);
字符串requestFormat=null;
if(invoke!=null)
{
requestFormat=this.GetRequestFormat(invoke,od);
}
string responseFormat=this.GetResponseFormat(get、invoke、od);
string uriTemplate=this.GetUriTemplate(get、invoke、od);
WebMessageBodyStyle bodyStyle=this.GetBodyStyle(get,invoke);
字符串requestSchemaLink=null;
字符串responseSchemaLink=null;
字符串requestExampleLink=null;
字符串responseExampleLink=null;
if(bodyStyle==WebMessageBodyStyle.Bare)
{
UriTemplate responseSchemaTemplate=新的UriTemplate(“帮助/{operation}/response/schema”);
responseSchemaLink=responseSchemaTemplate.BindByPosition(this.BaseUri,新字符串[]{od.Name}).AbsoluteUri;
UriTemplate responseExampleTemplate=新的UriTemplate(“help/{operation}/response/example”);
responseExampleLink=responseExampleTemplate.BindByPosition(this.BaseUri,新字符串[]{od.Name}).AbsoluteUri;
if(invoke!=null)
{
UriTemplate requestSchemaTemplate=新的UriTemplate(“help/{operation}/request/schema”);
requestSchemaLink=requestSchemaTemplate.BindByPosition(this.BaseUri,新字符串[]{od.Name}).AbsoluteUri;
UriTemplate requestExampleTemplate=新的UriTemplate(“帮助/{operation}/request/example”);
requestExampleLink=requestExampleTemplate.BindByPosition(this.BaseUri,新字符串[]{od.Name}).AbsoluteUri;
}
}
uriTemplate=HttpUtility.HtmlEncode(string.Format(“{0}/{1}”,this.BaseUri.AbsoluteUri,uriTemplate));
string xhtmlDescription=string.Format(“UriTemplate{0}方法{1}”,UriTemplate,方法);
如果(!string.IsNullOrEmpty(requestFormat))
{
xhtmlDescription=xhtmlDescription+string.Format(“请求格式{0}”,requestFormat);
}
if(requestSchemaLink!=null)
{
xhtmlDescription=xhtmlDescription+string.Format(“请求模式”,HttpUtility.HtmlEncode(requestSchemaLink));
}
if(requestExampleLink!=null)
{
xhtmlDescription=xhtmlDescription+string.Format(“请求示例”,HttpUtility.HtmlEncode(requestExampleLink));
}
xhtmlDescription=xhtmlDescription+string.Format(“响应格式{0}”,响应格式);
if(responseSchemaLink!=null)
{
xhtmlDescription=xhtmlDescription+string.Format(“响应模式”,HttpUtility.HtmlEncode(responseSchemaLink));
}
if(responseExampleLink!=null)
{
xhtmlDescription=xhtmlDescription+string.Format(“响应示例”,HttpUtility.HtmlEncode(responseExampleLink));
}
WebHelpAttribute help=od.Behaviors.Find();
if((help!=null)&&!string.IsNullOrEmpty(help.Comment))
{
xhtmlDescription=xhtmlDescription+string.Format(“Description{0}”,help.Comment);
}
xhtmlDescription=xhtmlDescription+“”;
var item=new SyndicationItem(){
Id=”http://tmpuri.org/“+od.名称,
内容=新的TextSyndicationContent(xhtmlDescription,TextSyndicationContentKind.XHtml),
LastUpdateTime=DateTime.UtcNow,
Title=newtextsyndictioncontent(string.Format(“{0}:{1}”,this.Description.Name,od.Name))
};
项目。添加(项目);
}
SyndicationFeed=新的SyndicationFeed()
{
Title=新文本辛迪加内容(“服务帮助页”),
LastUpdateTime=DateTime.UtcNow,
项目=项目
};
WebOperationContext.Current.OutgoingResponse.ContentType=“应用程序/atom+xml”;
返回feed.GetAtom10Formatter();
}
第一个和最后一个链接现在已失效。