Monday, March 26, 2012

Call Remote WebService. "Parameter count mismatch" Error

Hello All, I.m using AJAX for call remote WS. For example WS placed on localhost.

1) Here some web methods from WS (AJAXBridgeService WebSite)

  
 [WebMethod]
public string HelloWorld()
{
return"Hello World";
}

[WebMethod]
public Account GetAccountByID(int ID)
{
return new Account();
}

[WebMethod]
public string GetStringByID(int ID)
{
return ID.ToString();
}

[WebMethod]
public int GetIntByID(int ID)
{
return ID;
}

  2) i generated proxy class with wsdl utility and place it in App_Code (AJAXBridge WebSite) 
 3) i created asbx file

<bridge namespace="AJAXTest" className="Class">
<!-- change url to required --> <proxy type="AJAXTest.Service, App_Code"
serviceUrl="http://localhost/AjaxBridgeService/Service.asmx" /
<method name="HelloWorld"/
<method name="GetAccountByID">
<input>
<parameter name="ID"/>
</input>
</method
<method name="GetStringByID">
<input>
<parameter name="ID"/>
</input>
</method
<method name="GetIntByID">
<input>
<parameter name="ID"/>
</input>
</method>
</bridge>

 
4) then i used the following HTML+JS code 
<asp:ScriptManager ID="PageScriptManager"
runat="server"
LoadScriptsBeforeUI="False"
EnablePartialRendering="True">
<Services>
<asp:ServiceReference Path="bridges/bridge.asbx" />
</Services
<Scripts>
<asp:ScriptReference Path="bridge.js" />
</Scripts>
</asp:ScriptManager
<a href="javascript:void(0);" onclick="javascript:Click1();">Click Me 1</a> <span id="span1"></span>
<br/>
<a href="javascript:void(0);" onclick="javascript:Click2();">Click Me 2</a> <span id="span2"></span>
<br/>
<a href="javascript:void(0);" onclick="javascript:Click3();">Click Me 3</a> <span id="span3"></span
JS:
function Click1()
{
AJAXTest.Class.HelloWorld({}, OnComplete1, onError1);
}

function OnComplete1(obj)
{
var span = $get('span1');
span.innerHTML = obj;
}

function onError1(obj)
{
var span = $get('span1');
span.innerHTML = "Error:" + obj.get_message;
}

function Click2()
{
AJAXTest.Class.GetAccountByID({"ID" : 1}, OnComplete2, onError2);
}

function OnComplete2(obj)
{
var span = $get('span2');
span.innerHTML = obj;
}

function onError2(obj)
{
var span = $get('span2');
span.innerHTML = "Error:" + obj.get_message();
}

function Click3()
{
AJAXTest.Class.GetStringByID({"ID" : 100}, OnComplete3, onError3);
}

function OnComplete3(obj)
{
var span = $get('span3');
span.innerHTML = obj;
}

function onError3(obj)
{
var span = $get('span3');
span.innerHTML = "Error:" + obj.get_message();
}

 
5) After press "Click Me 1" link, i invoke HelloWorld and it returned string value to span,
then if i press "Click Me 2" or "Click Me 3"links, i got OnError and error message with "Parameter count mismacth".
There is a topic like thishttp://forums.asp.net/t/1136077.aspx
Does have anybody any information about call bridge with parameters? 
 
 
 
 
 



  
 
  


You may remove the jason-styled parameters.

In your javascript service invocation you may send the number only before the callbacks at this syntax:

AJAXTest.Class.GetAccountByID(1, OnComplete2, onError2);
(instead of AJAXTest.Class.GetAccountByID({"ID" : 1}, OnComplete2, onError2); )

Note: Don't send date this form, (you may send string instead and parse it on server side)


Vinija:

You may remove the jason-styled parameters.

In your javascript service invocation you may send the number only before the callbacks at this syntax:

? AJAXTest.Class.GetAccountByID(1, OnComplete2, onError2);
(instead of? AJAXTest.Class.GetAccountByID({"ID" : 1}, OnComplete2, onError2); )

Note: Don't send date this form, (you may send string instead and parse it on server side)

?

There we call remote web service via bridges technology, which demand of JSON input parameter.

I'm mot realy familiar with JSON syntax but according to the article you've referenced to, it seems that
you shouldn't write ID in quotation marks but simply write the word ID.

I'm not sure if it'll help you (you may have tried it already) but this is what I can see that by be wrong.

About the JSON input parameter, shouldn't the AJAX engine imlement the JSON serialization without
you actually write the parameters JSON styled?


<method name="HelloWorld"/
<method name="GetAccountByID">
<input>
<parameter name="ID"/> see here ...the parameter name is the same for all !!!has it got to be different?try and see it does not knw which parameter to invoke when clicked ,probably this might be an error
</input>
</method
<method name="GetStringByID">
<input>
<parameter name="ID"/>
</input>
</method
<method name="GetIntByID">
<input>
<parameter name="ID"/>
</input>
</method>
</bridge>

cheers

shankar

No comments:

Post a Comment