动态获取 asmx 服务的 Web 方法

发布于 2024-10-21 16:50:55 字数 290 浏览 2 评论 0原文

我们有许多 asmx 服务。我想为用户提供一个带有文本框的页面,用于输入服务网址,例如 http://abc.win .com/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 http://abc.win.com/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?

Appreciate your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅黛梨妆こ 2024-10-28 16:50:55

Kuul13 :您需要修改您的网络服务 URL,例如 http://abc.win.com/myservice /customerdata.asmx?wsdl 当用户单击加载按钮时。那么你可以使用我们的“ServiceDescription”类来获取wsdl描述,然后迭代它以获取“WebMethodInfoCollection”类中的方法名称。

要获取 SOAP 请求,您需要使用 SOAPExtension 类。这将为您提供 SOAP 请求和响应 XML。请参阅此链接:http://blog.encoresystems.net/articles/how-to-capture-soap-envelopes- when-consuming-a-web-service.aspx?www.microsoft.com

对于动态调用 webservice 看这篇 V.Good 文章
http://www.codeproject.com/KB/webservices/webservice_.aspx

有任何意见请回复我。

Kuul13 : You need to modify your webservice URL like http://abc.win.com/myservice/customerdata.asmx?wsdl when user clicks on load button. then you can use we "ServiceDescription" class to get wsdl description and then iterate that to get method names in 'WebMethodInfoCollection' class.

To get SOAP request you need to use SOAPExtension class.This will give you SOAP Request and Response XML.Refere this link for that : http://blog.encoresystems.net/articles/how-to-capture-soap-envelopes-when-consuming-a-web-service.aspx?www.microsoft.com

For dynamically calling webservice look a this V.Good article
http://www.codeproject.com/KB/webservices/webservice_.aspx

Please reply me for any comment.

树深时见影 2024-10-28 16:50:55
System.Net.WebClient client = new System.Net.WebClient();
System.IO.Stream stream = client.OpenRead("http://www.webservicex.net/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);
}
System.Net.WebClient client = new System.Net.WebClient();
System.IO.Stream stream = client.OpenRead("http://www.webservicex.net/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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文