PDA

View Full Version : [CLOSED] Pass array to web service



Maitreya
Mar 25, 2015, 10:02 AM
Hi,

I am calling a web service from an aspx page using the following code.



<Store>
<ext:Store ID="Store1" runat="server">
<Proxy>
<ext:AjaxProxy Url="~/Services/Search.asmx/Search" Json="true">
<Headers>
<ext:Parameter Name="Content-Type" Value="application/json" Mode="Value" />
</Headers>
</ext:AjaxProxy>
</Proxy>
<Parameters>
<ext:StoreParameter Name="Id" Value="Ext.getCmp('txtId').getValue()" Mode="Value" />
<ext:StoreParameter Name="type" Value="['S']" Mode="Raw" />
</Parameters>
</ext:Store>
</Store>



Web service:



[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)]
public ExtJsGrid<SearchResultsViewModel> Search
(
int start, string limit, string sort,
string Id, string[] type
)
{
}


I want to change type parameter to dynamically get the value from a code behind type (e.g. <%=type%>) instead of hard coding it as ['S'].

I tried different options but no luck so far. Can you please advice?

Thanks

Daniil
Mar 25, 2015, 12:10 PM
Hi @Maitreya,

Before suggesting anything, I should understand the requirement better.

Please clarify how do you manage the type value in code behind? How/when is it going to be changed?

Maitreya
Mar 25, 2015, 12:52 PM
Hi @Daniil,

"type" (char/string variable) is getting set from a query string value in the code behind page. It will only be set during the page load and will never be changed.

Thanks.

Daniil
Mar 25, 2015, 1:16 PM
Thanks. I would recommend to add a parameter during the page load as well.

string[] type = new string[] { "1", "2" };

store.Parameters.Add(new StoreParameter
{
Name = "type",
Value = JSON.Serialize(type),
Mode = ParameterMode.Raw
});

Maitreya
Mar 25, 2015, 1:52 PM
That's great! Thanks a lot.