使用反射来调用ASP.NET Web服务 [英] Using reflection to call an ASP.NET web service

查看:108
本文介绍了使用反射来调用ASP.NET Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个ASMX Web服务,为MyService。该服务有一个方法,的MyMethod。我可以如下在服务器端执行的MyMethod:

Say I have an ASMX web service, MyService. The service has a method, MyMethod. I could execute MyMethod on the server side as follows:

MyService service = new MyService();
service.MyMethod();

我需要做的差不多,不知道直到运行时服务和方法。

I need to do similar, with service and method not known until runtime.

我假设反思是去有关的方式。不幸的是,我有一个很难使其工作。当我执行这个code:

I'm assuming that reflection is the way to go about that. Unfortunately, I'm having a hard time making it work. When I execute this code:

Type.GetType("MyService", true);

它抛出这个错误:

It throws this error:

未能从程序集加载类型为MyService'App_Web__ktsp_r0,版本= 0.0.0.0,文化=中立,公钥=空'。

Could not load type 'MyService' from assembly 'App_Web__ktsp_r0, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.

任何指导,将AP preciated。

Any guidance would be appreciated.

推荐答案

我不知道这是否会是去它的最好方式。对我来说,最明显的方式,将是使一个HTTP请求,并用实际的HTTP GET或POST调用web服务。用你的方法,我不完全相信你会如何设置要发送到Web服务的数据。我已经添加了一些样本code在VB.Net

I'm not sure if this would be the best way to go about it. The most obvious way to me, would be to make an HTTP Request, and call the webservice using an actual HTTP GET or POST. Using your method, I'm not entirely sure how you'd set up the data you are sending to the web service. I've added some sample code in VB.Net

Dim HTTPRequest As HttpWebRequest
Dim HTTPResponse As HttpWebResponse
Dim ResponseReader As StreamReader
Dim URL AS String
Dim ResponseText As String

URL = "http://www.example.com/MyWebSerivce/MyMethod?arg1=A&arg2=B"

HTTPRequest = HttpWebRequest.Create(URL)
HTTPRequest.Method = "GET"

HTTPResponse = HTTPRequest.GetResponse()

ResponseReader = New StreamReader(HTTPResponse.GetResponseStream())
ResponseText = ResponseReader.ReadToEnd()

这篇关于使用反射来调用ASP.NET Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆