Monday, March 26, 2012

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

No comments:

Post a Comment