简体   繁体   English

动态加载.asmx Web服务

[英]Dynamically load .asmx web-service

I have an .aspx page that can perform a number of functions. 我有一个.aspx页面,可以执行许多功能。 The type of function is determined at run-time depending on which button the user clicks. 函数的类型在运行时取决于用户单击哪个按钮。 This makes makes a web-service call to an .asmx method. 这使得对.asmx方法进行Web服务调用。 The web-service call returns html and javascript which then become part of the original page. Web服务调用返回html和javascript,它们随后成为原始页面的一部分。

This new content has javascript events attached to button clicks, data validation etc. In turn these events then call their own web-service methods in another .asmx file. 此新内容具有与单击按钮,数据验证等相关的javascript事件。这些事件随后又在另一个.asmx文件中调用它们自己的网络服务方法。 The main page does not know about these other .asmx files when the page loads. 加载页面时,主页不了解其他这些.asmx文件。

So, is there any way of dynamically loading these .asmx files on demand? 那么,有没有办法按需动态加载这些.asmx文件?

You can create an assembly dynamically from the webservice, we do this where I work. 您可以从Web服务动态创建一个程序集,我们在我工作的地方进行。 Check out this codeproject link for an example that you can work from. 查看此codeproject链接以获取可以使用的示例。

(disclaimer, I only gave the codeproject page a quick once over to see that it should be a good start for what you want, it's along the same lines of what we do) (免责声明,我只给了codeproject页面一个快速的提示,以了解它应该是您想要的一个良好的开始,这与我们所做的工作是一致的)

"ASMX files" are not loaded. 未加载“ ASMX文件”。 They are files which define ASMX web services - which area called . 它们是定义ASMX Web服务的文件,该区域称为 You don't need to load these files. 您不需要加载这些文件。

Check out this link for the project code ! 查看此链接以获取项目代码 That helps you call the web service at run-time. 这可以帮助您在运行时调用Web服务。 You can save and reuse the web service structure. 您可以保存和重用Web服务结构。 There is a simple example: 有一个简单的例子:

//how to use service proxy
var factory = new ProxyFactory();
var service = factory.ImportService("www.site.net/webservice.asmx");

//how to call service method
var proxy = new Proxy(service.ServiceFile, service.ServiceName);
var result = proxy.InvokeMethod("CallMe", new ProxyMember("Id", 123));

//how to use method result
foreach (var item in result)
{
    var Id = item.Members["Id"].Value;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM