2016-07-31 82 views
0
被稱爲

您好我在我的網站上演示頁,我正在學習如何從腳本 這個調用Web服務是我的網頁 http://applicazioni.vsc300.it/Mediweb2015/Prova.aspx允許Web服務從腳本

$(document).ready(function() { 
 

 
          
 
    var params = { 'IDPaziente': 6586 } 
 
      $.ajax({ 
 
      "dataType": 'json', 
 
     "contentType": "application/json; charset=utf-8", 
 
     "type": "GET",  "url":"http://applicazioni.vsc300.it/Service.asmx/CercaPaziente", 
 
     "data": params, 
 
     "success": function (msg) { 
 
    var json = jQuery.parseJSON(msg.d); 
 
//valorizza texbox 
 
              $("#TXT_CognomePaziente").val(json.Denominazione); 
 
      }, 
 
     error: function (xhr, textStatus, error) { 
 
       alert(error); 
 
     } 
 
     }); 
 

 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 

 

 
<input name="TXT_CognomePaziente" type="text" id="TXT_CognomePaziente" name="TXT_CognomePaziente" />

並且這是服務:

' 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 Service 
    Inherits System.Web.Services.WebService 


    ' <WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, Method = "GET")> 
    <WebMethod()> _ 
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _ 
    Public Function CercaPaziente(IDPaziente As Integer) As String 
     Dim serialiser As JavaScriptSerializer = New JavaScriptSerializer() 

     Dim Paz As New CLS_Paziente 
     Paz.GetCercaAnagrafica(IDPaziente) 

     Dim serializer As JavaScriptSerializer = New JavaScriptSerializer() 
     Dim serializedItems As String = serializer.Serialize(Paz) 

     Return serializedItems 
    End Function 

End Class 

它返回一個錯誤,即只能通過腳本調用類定義上具有[ScriptService]屬性的Web服務。 但我啓用它! 我能做什麼?

+0

你能告訴你的JavaScript調用這個webservice嗎? –

+0

好的我做了:D 之前只有一個鏈接到我的測試頁面,現在我已經在問題 –

+0

上添加了javascript代碼,你已經解決了這個問題嗎? –

回答

0

this doc

如果多於一個屬性應用於一個單獨的程序元件,所述屬性被封閉在一組尖括號並以逗號彼此分隔。例如:

<Obsolete(), WebMethod()> 
Public Function PageCount(strURL As String) As Integer 

(這是很難找到,順便我找不到任何地方它在MSDN上。)所以,這是你的代碼沒有什麼,和.NET編譯器可能完全忽略了你的屬性。試試看看它是否有效:

<System.Web.Script.Services.ScriptService(), _ 
WebService(Namespace:="http://tempuri.org/"), _ 
WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1), _ 
Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> 
Public Class Service 
Inherits System.Web.Services.WebService