Showing posts with label call. Show all posts
Showing posts with label call. Show all posts

Wednesday, March 28, 2012

Accessing the pages server controls during webmethod calback

Hi,

Tell me please, when we call a webmethod during a callback, we send parameters through the javascript and dom to the webmethod on the server, right?

What if on the server I want, not only to access parameters sent from the javascript calling function, but I also want to acccess controls of the page, like other controls that didnt request the callback, like a gridview control or asp:textbox control, controls that re located on the page but that have nothing to do with the callback call.

Thanks a lot for your help.

PageMethods are static methods and have no access to controls on the page. However the client-side callback can access the DOM.

Monday, March 26, 2012

Accessing ASP.NET Profile

Hi,

How can I update Profile propertys in my Atlas application? Since I don't use update panels, I call web services to make server requests. I know that I can access the Session by declaring [WebMethod(EnableSession=true)], but can I also enable Profiles there?

Or are there alternatives to web services?

In javascript, you access profile properties using something like:

Sys.Profile.properties["list"] = [1, 2, 3];

And then you want to call:

Sys.Profile.save();

To enable this feature, you do need to have a few things in config defined:

<configSections>
<section name="profileService" type="Microsoft.Web.Configuration.ProfileServiceSection" requirePermission="false" />
</sectionGroup>
</configSections>

<microsoft.web>
<profileService enabled="true" getProperties="*" setProperties="*" />
</microsoft.web>

This will enable atlas access to the Profile object, and let you get and set all properties, note you can lock down which propeties you want get/settable thru atlas using the get/setProperties in the profileService section.

Hope that helps,
-Hao


Thank's a lot. After your reply I searched the atlas docs again and now I have no clue, why I overlooked the profile topic before!Wink [;)]

This feature is so cool!Cool [cool] I love Atlas more everyday...

Accessing a WebService-Method

Hello, i was migrating from Atlas July-CTP to Beta 2.

Now get an error when i call my webservice from javascript and the message is talking about System.InvalidOepration and authentication failed,

but only when I mark the corresponding method with EnableSession= true. In Atals JulyCTP the same call worked fine. Is there maybe a change in security-model?

Did I forget something or a declarartion is not set right?

Can anybody explain?

Hallo Michael,

can you show us the code of youre WebService definition?

Servus
Klaus


Check to see if your Web service definition has the ScriptService attribute (http://ajax.asp.net/docs/mref/8bb8cdde-6050-e492-e72a-eed2242c213c.aspx).
I believe the CTP version didn't have this attribute.


using System;

using System.IO;

using System.Web;

using System.Collections;

using System.Collections.Generic;

using System.Threading;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Xml.Serialization;

using System.Web.UI.WebControls;

using Microsoft.Web.Script.Services;

[ScriptService]

[WebService(Namespace ="http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

publicclass VehicleDataService : System.Web.Services.WebService

{

This Method is accessible, because it's called from Ajax:AutoCompleteExtender

[WebMethod(EnableSession =true)]

publicstring[] GetColors(string prefixText,int count)

{

string[] autoCompleteColors =null;

//Ablauf analog zu oben lediglich für Color statt für Model/Manufacturer

User user = SessionData.User;

if (autoCompleteColors ==null)

{

autoCompleteColors = VehicleDataUtils.GetColorsAsStringList(user);

}

int index =Array.BinarySearch(

autoCompleteColors, prefixText,

newCaseInsensitiveComparer());

if (index <0)

{

index = ~index;

}

int matchingCount;

for (matchingCount =0; matchingCount < count

&& index + matchingCount < autoCompleteColors.Length; matchingCount++)

{

if (!autoCompleteColors[index + matchingCount].StartsWith(

prefixText,StringComparison.CurrentCultureIgnoreCase))

{

break;

}

}

String[] returnValue =newstring[matchingCount];

if (matchingCount >0)

{

Array.Copy(autoCompleteColors, index, returnValue,0, matchingCount);

}

return returnValue;

}

This method is'nt accessible, it's called from pure javascript in a javascript-source file.

///<summary>

/// Setzt den aktuellen Hersteller (Name)

///</summary>

///<param name="input">Name des Herstellers</param>

[ScriptMethod]

[WebMethod(EnableSession =true)]

publicvoid SetActualManufacturer(string input)

{

SessionData.VehiclePageManufacturer = input;

}

}


Hello Michael,

maybe i'm wrong, but for me is VOID in a webservice a "not so god idee". You get absolut no response from this methode. It's not better to create an object with a returnvalue and react to the returnvalue?

It's only a idee.


The web service code seems OK. I don't know exactly how you're invoking the web service.
As you described, probably you don't have an aspx page with service reference configured using this web service. Adding a service reference to your page, makes AJAX download or include in the web page the proxy code (depending on the parameters you provide).
Check the proxy code that your service generates and see if it helps you (you can check that looking athttp://yourserverver/yourService.asmx/js - you just include /js after your web service address).

HTH,

Maíra

Access Denied error when attempting to consume web service

I am attempting to call a web service from my extender control, but when I do so, I get an error message - access denied (there are no other details). After some research, I think this has something to do with cross site scripting - since the web service exists elsewhere (it is a public webservice). How does one access an external webservice?

Here is the code that is throwing the error:

Sys.Net.WebServiceProxy.invoke(this.get_servicePath(),this.get_serviceMethod(),false, params,

Function.createDelegate(this,this._onMethodComplete),

Function.createDelegate(this,this._onMethodFailed));

ServicePath="http://www.webservicex.net/uszip.asmx"ServiceMethod="GetInfoByZIP"

Check out this article:

http://dotnetslackers.com/columns/ajax/MashitUpwithASPNETAJAX.aspx

Hope this helps,

Elias.

Wednesday, March 21, 2012

A more advanced AutoCompleteExtender?

I've been playing around with the AutoCompleteExtender and it's pretty easy to use. Is there anyway to better control when to call the webservice? For instance, right now it calls the webservice after the 3rd character of a textbox is typed in. What happens if i want the webservice called on the first or second character is type in? Is this possible?Hi,

yes it is, but you have to modify the Extender control. Checkthis article from my blog.
Ah, extending the control. Thanks, and good tips on your blog too. Subscribed.

Looks like the MarchCTP bits has a MinimumPrefixLength property for the AutoCompleteProperties class. So no need to modify the Extender control anymore.Cool [cool]

AutoCompleteProperties MinimumPrefixLength Property

A circular reference was detected while serializing an object of type "System.goblaization

Hi all,

I am trying to call a webservice through javascript to return a dataset to bind it to a datagrid on the client side.

I am using a scriptmanager and registered the service by setting the service path.

I am calling a method on a Textbox onKeydown event to call the webservice method. The web service is returning the a data set. But the problem is am geting an exception stating the following

The server method 'GetDataSet' failed with the following error: System.InvalidOperationException-- A Circular reference was detected while serializing an object of type "System.Globalization.CultureInfo"

Please help me out.

See the following code to get an idea about the problem i have

<WebMethod(EnableSession:=True)> _

PublicFunction GetDataSet(ByVal prefixTextAsString)As DataSet

Dim dtAs DataTable

dt =New DataTable

Dim drAs DataRow

dt =Me.GetSelectedTestSchema()

dr =Me.PopulateSelectedTestsRow("1020","dafda", dt)

Try

dt.Rows.Add(dr)

Catch exAs Exception

EndTry

Dim dsAs DataSet =New DataSet()

ds.Tables.Add(dt)

Return ds

EndFunction

Javascript code

function GenerateGrid()

{

var myGrid = igtbl_getGridById("grdSelectedTests");

TestListService.GetDataSet("x",OnWebRequestComplete);

// myGrid.Control.Set_DataDataSource(TestListService.GetDataSet("x").Table[0]);

//

}

function OnWebRequestComplete(results)

{

'I am using the Infragistics ultraWebgrid

var grdControl = igtbl_getGridById("grdSelectedTests");

grdControl.control.set_data(results);

}

Scriptmanager code

<asp:ScriptManagerID="ScriptManager1"runat="server">

<Services>

<asp:ServiceReferencePath="../AutoCompleteServices/TestListService.asmx"/>

</Services>

</asp:ScriptManager>

Hi,

According to my understanding to your problem, I don't think it's a AJAX specific issue. The exception is related to your server side code.

Can you debug your server side code to try to solve it?

Or you may post the code for methods:GetSelectedTestSchema() andPopulateSelectedTestsRow here.


We are marking this issue as "Answered". If you have any new findings or concerns, please feel free to unmark the issue.


I too am having the same problems.

I'm using C# to write my webservice, I have almost an identical setup for the client-side scripts.


I get this error even when returning an empty DataSet.


 [WebMethod]public DataSet GetData() {return new DataSet(); }

Does anyone know what this error message is telling me? I tried debugging it, and no exception is thrown from the webservice and it works fine when I send a soap request to it.

Thanks,

Lee


You may try to overcome it by setting response format to XML. For instance:

[System.Web.Script.Services.ScriptMethod(ResponseFormat=System.Web.Script.Services.ResponseFormat.Xml)]
public DataSet GetData()
{