C# 使用C动态调用SOAP#
我使用以下代码动态调用SOAP方法。当服务的输入为一(1)时,它工作。当我将输入增加到2时,它返回错误 不知道为什么会这样 我引用此链接来构建此。。 我的SOAP服务:C# 使用C动态调用SOAP#,c#,asp.net,web-services,soap,dynamically-generated,C#,Asp.net,Web Services,Soap,Dynamically Generated,我使用以下代码动态调用SOAP方法。当服务的输入为一(1)时,它工作。当我将输入增加到2时,它返回错误 不知道为什么会这样 我引用此链接来构建此。。 我的SOAP服务: [WebMethod] public string UpdateMapString(string status, string astationid) { return string.Format("Update Completed"); } 这是我调用SOAP服务的C#代码 主要功能:
[WebMethod]
public string UpdateMapString(string status, string astationid)
{
return string.Format("Update Completed");
}
这是我调用SOAP服务的C#代码
主要功能:
private MethodInfo[] methodInfo;
private ParameterInfo[] param;
private Type service;
private Type[] paramTypes;
public List<Type> myproperty = new List<Type>();
private string MethodName = "";
public List<string> treews = new List<string>();
public List<string> treeParameters = new List<string>();
public static void Main(string[] args)
{
Program a = new Program();
a.DynamicInvocation();
a.selectMethod();
a.invoke();
Console.ReadLine();
}
要获取方法,请执行以下操作:
public void selectMethod()
{
treeParameters.Add(treews[0]);
MethodName = methodInfo[0].Name;
param = methodInfo[0].GetParameters();
/// myProperty.add = param[e.Node.Index].ParameterType;
myproperty.Add(param[0].ParameterType);
// Console.WriteLine("This is param: " + param[0].ToString());
// myProperty = new properties(param.Length);
// Get the Parameters Type
paramTypes = new Type[param.Length];
for (int i = 0; i < paramTypes.Length; i++)
{
paramTypes[i] = param[i].ParameterType;
}
foreach (ParameterInfo temp in param)
{
treeParameters.Add(temp.ParameterType.Name + " " + temp.Name);
}
}
public void selectMethod()
{
添加(treews[0]);
MethodName=methodInfo[0]。名称;
param=methodInfo[0]。GetParameters();
///myProperty.add=param[e.Node.Index].ParameterType;
myproperty.Add(参数[0].ParameterType);
//WriteLine(“这是param:+param[0].ToString());
//myProperty=新属性(参数长度);
//获取参数类型
参数类型=新类型[参数长度];
for(int i=0;i
调用服务(此函数中出现错误)
public void invoke()
{
Console.WriteLine(“Invoke:”);
object[]param1=新对象[param.Length];
尝试
{
对于(int i=0;i
请澄清您的具体问题或添加其他详细信息,以突出显示您所需的内容。正如目前所写的,很难准确地说出你在问什么。请参阅How to Ask页面以获得澄清此问题的帮助。我此行有错误//******************此行有错误Object response=t.Invoke(obj,param1)//*****************这一行有错误
public void selectMethod()
{
treeParameters.Add(treews[0]);
MethodName = methodInfo[0].Name;
param = methodInfo[0].GetParameters();
/// myProperty.add = param[e.Node.Index].ParameterType;
myproperty.Add(param[0].ParameterType);
// Console.WriteLine("This is param: " + param[0].ToString());
// myProperty = new properties(param.Length);
// Get the Parameters Type
paramTypes = new Type[param.Length];
for (int i = 0; i < paramTypes.Length; i++)
{
paramTypes[i] = param[i].ParameterType;
}
foreach (ParameterInfo temp in param)
{
treeParameters.Add(temp.ParameterType.Name + " " + temp.Name);
}
}
public void invoke()
{
Console.WriteLine("Invoke:");
object[] param1 = new object[param.Length];
try
{
for (int i = 0; i < param.Length; i++)
{
//param1[i] = Convert.ChangeType(myProperty.MyValue[i], myProperty.TypeParameter[i]);
// Console.WriteLine(myproperty[i].ToString());
param1[i] = Convert.ChangeType("10", typeof(string));
}
foreach (MethodInfo t in methodInfo)
{
//Console.WriteLine("Tname: " + t.Name.ToString());
if (t.Name == MethodName)
{
//Invoke Method
Object obj = Activator.CreateInstance(service);
//*****************error at this line
Object response = t.Invoke(obj, param1);
//*****************error at this line
// Console.WriteLine(t.Name);
Console.WriteLine(response.ToString());
break;
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
//MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}