0 Replies - 2385 Views - Last Post: 24 November 2009 - 10:08 AM Rate Topic: -----

#1 azjata   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 24-November 09

ASP.NET Asmx webservice using Membership called from Ajax

Posted 24 November 2009 - 10:08 AM

Hello, I have a following problem.
I am using SqlMembershipProvider on SQL Server 2005 for authentication, basically logging in registering and the rest of functionality works fine. But when I am trying to use the webservice (which is in the same project) from ajax, I am getting error

Message: Sys.Net.WebServiceFailedException: The server method 'getUser' failed with the following error: System.NullReferenceException-- Object reference not set to an instance of an object.

I am using script manager through which i call the webservice in ajax, i also tried to do it in classical way with http post, but without any changes, I checked and the proxy for the webservice is created (I checked it with webservice/js ). And now i have run out of ideas...

here is the code where I am getting error...

This is webservice

using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Web.Security;
using System.Data.SqlTypes;
using System.Web.Script.Services;

/// <summary>
/// Summary description for UserGet
/// </summary>
[WebService(Namespace = "http://localhost")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]

public class UserGet : System.Web.Services.WebService {

	public UserGet () {

		//Uncomment the following line if using designed components 
		//InitializeComponent(); 
	}

	[WebMethod]
	public List<User> getUser()
	{

		DataSQLDataContext dc = new DataSQLDataContext();
		System.Data.SqlTypes.SqlGuid guid = new System.Data.SqlTypes.SqlGuid(Membership.GetUser().ProviderUserKey.ToString());
		var query = from u in dc.Users
					where u.UserID == guid.Value
					select u;


		return query.ToList();

	}
}




This is where I am getting the error

<%@ Page Title="" Language="C#" MasterPageFile="~/master/footerPlaceHolder.master" AutoEventWireup="true" CodeFile="EditUser.aspx.cs" Inherits="members_Maps" %>
<%@ MasterType VirtualPath="~/master/footerPlaceHolder.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentMainPlaceHolder" Runat="Server">
	<center style="height: 347px">
		<asp:ScriptManager ID="jscriptManager" runat="server" EnableScriptGlobalization="True" EnablePageMethods="True"  EnableHistory="True">
		<Services>
		<asp:ServiceReference Path="~/UserGet.asmx" />
		</Services>
			<scripts>
			<asp:ScriptReference  Path="~/jquery/jquery-1.3.2.js" />
			</Scripts>
		</asp:ScriptManager>
	<div id="map_canvas" style="height: 297px; width: 414px;"/>
		 <script type="text/javascript">

 [u]		   UserGet.getUser(userDataSuccess);[/u]
		
	function userDataSuccess(data) {
					  if(data!=null) {
					userData = data;
				   if (data[0].lat == undefined && data[0].lang == undefined) {
					   showAddress(data[0].address, data[0].city, data[0].country);
				   }
				   else {
				   window.location = "EditGroup.aspx";
					}
				}
			}




and this is Web Config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<configSections>
		<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
			<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
				<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
				<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
					<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
					<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
					<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
					<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /></sectionGroup></sectionGroup></sectionGroup></configSections><appSettings />
	<connectionStrings>
  <add connectionString="Data Source=AZJATA-PC\SQLEXPRESS;Initial Catalog=Gmaps;User ID=mattSQL;Password=*****" name="GmapsConnectionString2" providerName="System.Data.SqlClient" />

  </connectionStrings>
	<system.web>
		<!-- 
			Set compilation debug="true" to insert debugging 
			symbols into the compiled page. Because this 
			affects performance, set this value to true only 
			during development.
		-->
  <roleManager enabled="true">
   <providers>
				<remove name="AspNetWindowsTokenRoleProvider" />
	<remove name="AspNetSqlRoleProvider" />
	<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="GmapsConnectionString2" applicationName="YourVillage" />
   </providers>
  </roleManager>
  <compilation debug="true" defaultLanguage="c#">
   <assemblies>
	<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
	<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
	<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
	<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
	<add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
	<add assembly="System.Data.Services, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
	<add assembly="System.Data.Services.Client, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
	<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
	<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
   </assemblies>
  </compilation>
		<!--
			The <authentication> section enables configuration 
			of the security authentication mode used by 
			ASP.NET to identify an incoming user. 
		-->
		<authentication mode="Forms">
   <forms loginUrl="Default.aspx" defaultUrl="Default.aspx" protection="None" timeout="120" />
  </authentication>
		<!--
			The <customErrors> section enables configuration 
			of what to do if/when an unhandled error occurs 
			during the execution of a request. Specifically, 
			it enables developers to configure html error pages 
			to be displayed in place of a error stack trace.

		<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
			<error statusCode="403" redirect="NoAccess.htm" />
			<error statusCode="404" redirect="FileNotFound.htm" />
		</customErrors>
		-->
		<membership defaultProvider="CustomizedProvider">
   <providers>
	<remove name="AspNetSqlMembershipProvider" />
	<add connectionStringName="GmapsConnectionString2" applicationName="YourVillage" minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0" name="CustomizedProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   </providers>
  </membership>
		<pages>
			<controls>
				<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
				<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /></controls></pages>
		<httpHandlers>
			<remove verb="*" path="*.asmx" />
			<add verb="*" path="*.asmx" validate="true" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
			<add verb="*" path="*_AppService.axd" validate="true" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
			<add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

	</httpHandlers>
		<httpModules>
			<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /></httpModules>
		<identity impersonate="true" /></system.web>
	<system.codedom>
		<compilers>
			<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
			<providerOption name="CompilerVersion" value="v3.5" />	
				<providerOption name="WarnAsError" value="false" /></compiler></compilers></system.codedom>
	<!-- 
		The system.webServer section is required for running ASP.NET AJAX under Internet
		Information Services 7.0.  It is not necessary for previous version of IIS.
	-->
	<system.webServer>
		<validation validateIntegratedModeConfiguration="false" />
		<modules>
			<remove name="ScriptModule" />
			<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /></modules>
	<handlers>
			<remove name="WebServiceHandlerFactory-Integrated" />
			<remove name="ScriptHandlerFactory" />
			<remove name="ScriptHandlerFactoryAppServices" />
			<remove name="ScriptResource" />
	  <add name="ScriptHandlerFactory" verb="*" path="*.asmx"  preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
			<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
		<add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /></handlers>
		<defaultDocument>
			<!--<files>
				<remove value="Default.asp" />
				<remove value="Default.htm" />
				<add value="Default.aspx" />
			</files>-->
		</defaultDocument></system.webServer>
	<runtime>
		<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
			<dependentAssembly>
				<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" />
				<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /></dependentAssembly>
			<dependentAssembly>
				<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" />
				<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /></dependentAssembly></assemblyBinding></runtime>
</configuration>





Any ideas?

Thanks a lot!

Is This A Good Question/Topic? 1

Page 1 of 1