0

I am using simple json method for calling webmethod but it works with aspx file ie url:

'myclass.aspx/myfunction'

but it doesnt work if I put same function in an asmx file and change url to asmx.

Is there anything else have to be done to enable asmx service ?

asmx with vb code: // this works

<%@ WebService Language="VB" Class="WebService" %>

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public Class WebService
    Inherits System.Web.Services.WebService

    <System.Web.Services.WebMethod()> _
    <System.Web.Script.Services.ScriptMethod()> _
    Public Function abc(ByVal args As String) As String
               Return returnValue
    End Function

End Class

asmx with codebehind file

<%@ WebService Language="VB"  CodeBehind="default.vb" Class="default" %> //this doesnt work

code behind file

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class mintnow_default
    Inherits System.Web.Services.WebService

    <System.Web.Services.WebMethod()> _
    <System.Web.Script.Services.ScriptMethod()> _
    Public Function abc(ByVal args As String) As String
               Return returnValue
    End Function

End Class
Christian Strempfer
  • 7,291
  • 6
  • 50
  • 75
Ironsun
  • 801
  • 2
  • 8
  • 19

2 Answers2

1

You need to decorate your service with the <ScriptService> attribute if you want to be able to invoke it with a JSON request:

' you need to add the ScriptService attribute here
<System.Web.Script.Services.ScriptService>
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public Class WebService1
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function MyFunction() As String
       Return "Hello World"
    End Function

End Class
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

You will have to remove the Shared keyword from the service methods.

John Saunders
  • 160,644
  • 26
  • 247
  • 397