如何取得项目中所有的web引用

grradffer 2008-07-03 04:45:42
如题,怎样取得项目中所有引用的webservice代理类?
...全文
68 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
grradffer 2008-07-04
  • 打赏
  • 举报
回复
有什么办法除了能获得类信息外 还能取得更多所有引用的webservice的信息?
我想要做个统一的webservice管理中心
jeremyyang824 2008-07-04
  • 打赏
  • 举报
回复

/// <summary>
/// 取得所有webservice代理类
/// </summary>
/// <returns></returns>
private List<Type> GetWebServiceClassList()
{
List<Type> webServiceList = new List<Type>();
Assembly[] assemblys = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblys)
{
if (assembly.GlobalAssemblyCache) continue;
//if (assembly.FullName.IndexOf("App_WebReferences") < 0) continue;//可选,提高效率

Type[] types = assembly.GetExportedTypes();
foreach (Type t in types)
{
if (t.IsClass && typeof(System.Web.Services.Protocols.SoapHttpClientProtocol).IsAssignableFrom(t))
{
webServiceList.Add(t);
}
}
}
return webServiceList;
}
春天的气息 2008-07-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jeremyyang824 的回复:]
C# code
/// <summary>
/// 取得所有webservice代理类
/// </summary>
/// <returns></returns>
private List<Type> GetWebServiceClassList()
{
List<Type> webServiceList = new List<Type>();
Assembly[] assemblys = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblys)
{
if (assembly.GlobalAssemblyCac…
[/Quote]
honkerhero 2008-07-04
  • 打赏
  • 举报
回复
楼上的对
jeremyyang824 2008-07-04
  • 打赏
  • 举报
回复
楼主可以遍历添加Web引用的文件夹,如App_WebReferences,过滤出所有的wsdl文件,然后使用System.Web.Services.Description.ServiceDescription类的Read方法读取该wsdl文件。
wsdl包括了所有相关信息,前提是楼主对其格式以及意义比较了解。
SSXYC 2008-07-04
  • 打赏
  • 举报
回复
没写过,帮顶
jzywh 2008-07-03
  • 打赏
  • 举报
回复

Type baseType = typeof(System.Web.Services.Protocols.SoapHttpClientProtocol);

Type[] allClasses = typeof(YourClass).Assembly.GetTypes();

foreach (Type type in allClasses)
{
if (type.IsSubclassOf(baseType))
{
Console.WriteLine(type.ToString());
}
}

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧