动态获取Asmx服务的Web方法

编程入门 行业动态 更新时间:2024-10-27 14:18:17
本文介绍了动态获取Asmx服务的Web方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们有大量的asmx服务.我想给用户一个带有文本框的页面来输入服务URL,例如 abc.win /myservice/customerdata.asmx .当用户点击加载"按钮时,我会动态地将所有Web方法添加到下拉列表中.我需要一些提示: 1.如何动态获取所有方法? 2.如何获取所选方法的SOAP请求?这样,我们就可以用实际值替换参数值了吗?

We have number of asmx services. I want to give an user a page with a textbox to input service url like abc.win/myservice/customerdata.asmx. When user hit "Load" button, dynamically I add all the web methods to the dropdown. I need some pointers: 1. How to dynamically get all the methods? 2. How can I get the SOAP request for the method selected? So that, we can replace the parameter values with actual values?

感谢您的帮助.

推荐答案

System.Net.WebClient client = new System.Net.WebClient(); System.IO.Stream stream = client.OpenRead("www.webservicex/globalweather.asmx?wsdl"); ServiceDescription description = ServiceDescription.Read(stream); ServiceDescriptionImporter importer = new ServiceDescriptionImporter(); importer.ProtocolName = "Soap12"; importer.AddServiceDescription(description, null, null); importer.Style = ServiceDescriptionImportStyle.Client; importer.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.GenerateProperties; CodeNamespace nmspace = new CodeNamespace(); CodeCompileUnit unit1 = new CodeCompileUnit(); unit1.Namespaces.Add(nmspace); ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit1); if (warning == 0) { CodeDomProvider provider1 = CodeDomProvider.CreateProvider("CSharp"); string[] assemblyReferences = new string[2] { "System.Web.Services.dll", "System.Xml.dll" }; CompilerParameters parms = new CompilerParameters(assemblyReferences); CompilerResults results = provider1.CompileAssemblyFromDom(parms, unit1); object[] args = new object[1]; args[0] = "India"; object wsvcClass = results.CompiledAssembly.CreateInstance("GlobalWeather"); MethodInfo mi = wsvcClass.GetType().GetMethod("GetCitiesByCountry"); RegExpForCountryCity(mi.Invoke(wsvcClass, args).ToString()); } else { Console.WriteLine("Warning: " + warning); } void RegExpForCountryCity(string strHTML) { Regex qariRegex = new Regex(@"<Table>\s*<Country>(?<Country>[\s\S]*?)</Country>\s*<City>(?<City>[\s\S]*?)</City>\s*</Table>", RegexOptions.IgnoreCase | RegexOptions.Multiline); MatchCollection mc = qariRegex.Matches(strHTML); string strCountryCity = ""; for (int i = 0; i < mc.Count; i++) { if (string.IsNullOrEmpty(strCountryCity)) strCountryCity = "Country: " + "<b>" + mc[i].Groups["Country"].Value + "</b>" + " " + "City: " + "<b>" + mc[i].Groups["City"].Value + "</b>" + "</br>"; else strCountryCity += "</br>" + "Country: " + "<b>" + mc[i].Groups["Country"].Value + "</b>" + " " + "City: " + "<b>" + mc[i].Groups["City"].Value + "</b>" + "</br>"; } Response.Write(strCountryCity); }

更多推荐

动态获取Asmx服务的Web方法

本文发布于:2023-10-07 10:51:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469194.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   动态   Asmx   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!