Home > Net >  When reflection calls WebService "argument count does not match"
When reflection calls WebService "argument count does not match"

Time:05-21

There was a 'reflection calls WebService parameter count does not match,
No problem when passing a parameter, how to pass multiple parameters?

 
One, called
Public void GetProduct () {
String iri="http://localhost:61263/WebServiceTest.asmx";
Var action="GetCustomerByName";
Object [] objParm=new Object [] {1, 2};

WebServiceProxy web=new WebServiceProxy (iri, action, ref errMsg);
Var result=web. ExecuteQuery (action, objParm, ref errMsg);
}

Public object ExecuteQuery (string methodName, object [] param, ref string errMsg, int timeOut=3000) {

ErrMsg=string. The Empty;
The object rtnObj=null;
Try {
If (this. _typeName==null) {
ErrMsg="Web services to access the name of the class [" + enclosing _wsdlName +"] is not correct, please check!" ;
return null;
}

//call the method
MethodInfo mi=this. _typeName. GetMethod (methodName);
If (mi==null) {
ErrMsg="Web services to access the method name [" + methodName +"] is not correct, please check!" ;
return null;
}
Try {

If (param==null)
RtnObj=mi. Invoke (Instance, null);
The else {
RtnObj=mi. Invoke (Instance, param);
}
{} the catch (Exception tle)
ErrMsg=$" Web services to access methods error: [{methodName}] {tle. Message}, please check!" ;
}

{} the catch (Exception ex)
ErrMsg=ex. Message + ";" + ex. InnerException;
}
Return rtnObj;
}

Second, web service method
[the WebMethod]
Public int GetCustomerByName (int the age, int salary) {//transfer into 0?
Return the age + salary;
}
  •  Tags:  
  • C#
  • Related