2012-01-25 6 views
0

私はWebMethod属性 を呼び出すための単純なJSONの方法を使用していますが、それはASPXファイルすなわちURLで動作します:pagemethodはasmxファイルではなく、aspx any suggesionから機能しませんか?

'myclass.aspx/myfunction' 

が、それは私がASMXファイルに同じ機能を置けば仕事とASMXにURLを変更doesntの。

asmxサービスを有効にするために必要なことはありますか?

VBのコードとASMX://あなたからSharedキーワードを削除する必要がありますファイル

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 

答えて

0

の背後に、この分離コードファイルで

<%@ 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を作品

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

コードサービスメソッド。

+0

うーん何exavtly staticキーワード??私はあなたを取得しません – Ironsun

+0

自動生成されたasmxは、コメントを解除すると言う_この行を行ったが、そのntの作業 – Ironsun

+0

ページメソッドは、例えば、 'public static int SomeMethod(int param ) '。 '静的'を取り除く。 –

1
あなたはJSONリクエストでそれを呼び出すことができるようにしたい場合は <ScriptService>属性を使用してサービスを飾るために必要

' 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 
+0

私はその行 _ – Ironsun

+0

を追加しましたが、動作しませんでした:( – Ironsun

+0

@ user1167053、どのように正確にあなたはjavascriptからそれを呼び出すのですか? –

関連する問題