我自己随便写了一个简单的webservice
如下using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;[WebService(Namespace = "http://www.test.com/webservices/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () { //Uncomment the following line if using designed components
//InitializeComponent();
} public struct Test
{
public string str;
public int num;
} [WebMethod] public string TestFun(Test ts)
{
return ts.str + ts.num.ToString();
}
}我准备动态调用它。
调用它,我采用了一个网上找到的例子,一个类,大家可以去它原来的地址看一下,
http://www.crowsprogramming.com/archives/66/comment-page-1#comment-606
因为无法贴到这里,否则会超过字数限制。
对造成的不便,感到很歉意,确实是无法粘贴。
现在的问题是呢,我可以用他调用普通的webservice里的函数。就是那种比较简单的输入类型的那种。
但是我刚写的这个,他的参数是一个struct,我就不知道如何动态调用了。
而且我发现此时,AvailableServices有两个,一个是 Service, 一个就是我建立的那个Test (那个struct)而且对应于Test,这个AvailableService,它还有4个方法,分别是 get_str, set_str, get_num, set_num十分困惑,不知道如何动态调用这个方法。
有相关经验的人来看一下吗?
谢谢,十分感谢,我的积分不多,否则一定大大奉上。
如下using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;[WebService(Namespace = "http://www.test.com/webservices/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () { //Uncomment the following line if using designed components
//InitializeComponent();
} public struct Test
{
public string str;
public int num;
} [WebMethod] public string TestFun(Test ts)
{
return ts.str + ts.num.ToString();
}
}我准备动态调用它。
调用它,我采用了一个网上找到的例子,一个类,大家可以去它原来的地址看一下,
http://www.crowsprogramming.com/archives/66/comment-page-1#comment-606
因为无法贴到这里,否则会超过字数限制。
对造成的不便,感到很歉意,确实是无法粘贴。
现在的问题是呢,我可以用他调用普通的webservice里的函数。就是那种比较简单的输入类型的那种。
但是我刚写的这个,他的参数是一个struct,我就不知道如何动态调用了。
而且我发现此时,AvailableServices有两个,一个是 Service, 一个就是我建立的那个Test (那个struct)而且对应于Test,这个AvailableService,它还有4个方法,分别是 get_str, set_str, get_num, set_num十分困惑,不知道如何动态调用这个方法。
有相关经验的人来看一下吗?
谢谢,十分感谢,我的积分不多,否则一定大大奉上。
解决方案 »
- DataGridView问题,疑难问题请教高手!!!!!!!!!
- 谁能提供一个注册版的加壳混淆工具啊。
- 老师不是的题目,帮看看答案对吗
- 各位朋友帮忙。帮我完成这个存储过程吧。谢谢。
- 在ado.net中,关闭连接后,还可以执行存储过程吗????
- 问个问题麻烦指点一下
- 在制作安装程序的时候,我在注册表编辑器中写了键值,可是安装的时候却没有写入注册表中,为什么啊?
- 单击ReportView,弹出窗体
- C#怎么实现控件登陆网址(求代码)
- ParentGridView.Rows[i].Cells[id_index].Text 取不到值的问题
- 关于打印的问题 希望大家帮忙(急)
- 类、结构或接口成员声明中的标记无效
用反射创建它的实例,给它的字段赋值,当做参数传递给调用的方法就行了
但是创建出来复制给谁啊???
object o =Activator.CreateInstance(assemblyName, typeName);
.....
o.GetType().GetProperties()获得属性列表
遍历属性列表,为每个PropertyInfo SetValue()。
需要注意struct通过wsdl导入后到底是什么类型,这个我不太清楚,它的成员是属性还是字段。
o.GetType().GetField("Name").SetValue(o, "abc");//GetField或者GetProperty,看你的具体情况
o.GetType().GetField("Id").SetValue(o, 100);
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace cbClass
{ [System.Web.Services.WebServiceBindingAttribute(Name = "userValidateSoap", Namespace = "http://www.test.com/webservices/")]
public class serviceClass : System.Web.Services.Protocols.SoapHttpClientProtocol
{
public serviceClass()
{
this.Url = "http://www.test.com/webservices/servicesA.asmx";
}
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.test.com/webservices/TestFun", RequestNamespace = "http://www.test.com/webservices/", ResponseNamespace = "http://www.test.com/webservices/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string TestFun(Test ts)
{
try
{
object[] results = this.Invoke("TestFun", new object[] {
ts});
return (string)(results[0]);
}
catch { return false; }
}
}
}
太感谢你了。谢谢。
ps: 我用的GetProperty另外,我用
o.GetType().InvokeMember("set_str", BindingFlags.InvokeMethod, null, obj, arg);
o.GetType().InvokeMember("set_num", BindingFlags.InvokeMethod, null, obj, arg);
也可以用,但明显不如你那个好。谢谢谢谢