Visualizzazione dei risultati da 1 a 9 su 9
  1. #1

    non richiama WebMethod() in asmx jquery asp.net

    Ciao a tutti, ho il problema che non mi compare nulla a vide richiamando una <WebMethod()>, ho fatto vari tentativi con percorsi e dati diversi ed altre prove (da smanettone). Questo codice è copiato da un esempio ma anche questo non funziona. La pagina è aspx ed è sotto ad una masterpage

    codice HTML:
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>
    <div><br />sotto</div><div> <div>Your Name :<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox><input id="btnGetTime" type="button" value="Show Current Time"    onclick = "Hello" /></div><Button ID="cmdSave"  title="CLICCAMI" onclick = "Hello()" class="btn"></Button></div>  <div>       <table>    <tbody>        <tr>            <th>                Value 1:            </th>            <td>                <asp:TextBox ID="txtValue1" runat="server" />            </td>        </tr>        <tr>            <th>                Value 2:            </th>            <td>                <asp:TextBox ID="txtValue2" runat="server" />            </td>        </tr>    </tbody></table></div> <asp:Button ID="btnGo" Text="Go" OnClientClick="CallService(); return false;" runat="server" /> <asp:Label ID="lblResult" Text="&nbsp;" Width="100%" runat="server" />
    	<style> .loading{ background-image: url('ajax-loader.gif'); background-repeat: no-repeat;}	</style>
    <script type="text/javascript">
    function CallService() {
    $.ajax({
    type: "POST",
    url: "http://localhost:4587/asmx/Add",
    data: "{ 'value1': " + $("#txtValue1").val() + ", 'value2': " + $("#txtValue2").val() + "}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: OnSuccess,
    error: OnError
    });
    }


    function OnSuccess(data, status) {
    $("#lblResult").html(data.d);
    }


    function OnError(request, status, error) {
    $("#lblResult").html(request.statusText);
    }
    </script>


    <script type="text/javascript">
    function CallService() {
    $("#lblResult").addClass("loading");
    $.ajax({
    type: "POST",
    url: "http://localhost:4587/MS.asmx/HelloWorld",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: Success,
    error: Error
    });
    }


    function Success(data, status) {
    $("#lblResult").removeClass("loading");
    $("#lblResult").html(data.d);
    }


    function Error(request, status, error) {
    $("#lblResult").removeClass("loading");
    $("#lblResult").html(request.statusText);
    }
    </script>
    codice:
    
    
    Grazie a tutti
    Riccardo Rossi - Smart Agent 3

    GENIALTEK il tuo sito presto e bene
    www.genialtek.it

  2. #2
    Ho corretto :
    url: "http://localhost:4587/WS.asmx/Add",

    Cancellata la seconda function CallService()

    Putroppo ancora non va
    Riccardo Rossi - Smart Agent 3

    GENIALTEK il tuo sito presto e bene
    www.genialtek.it

  3. #3
    Moderatore di ASP.net L'avatar di djciko
    Registrato dal
    Nov 2002
    Messaggi
    6,886
    ma il WS è avviato ?
    ti fa vedere il wsdl ?

  4. #4
    Ciao, grazie della risposta,
    ho provato a lanciare direttamente la pagina ws.asmx mi risponde con i metodi inseriti (helloworld ed un altro) e questo codice:

    SOAP 1.2
    POST /WS.asmx HTTP/1.1Host: localhost
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: length

    <?xml version="1.0" encoding="utf-8"?>
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
    <soap12:Body>
    <GetDetails xmlns="http://tempuri.org/">
    <name>string</name>
    <age>int</age>
    </GetDetails>
    </soap12:Body>
    </soap12:Envelope>HTTP/1.1 200 OK
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: length

    <?xml version="1.0" encoding="utf-8"?>
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
    <soap12:Body>
    <GetDetailsResponse xmlns="http://tempuri.org/">
    <GetDetailsResult>string</GetDetailsResult>
    </GetDetailsResponse>
    </soap12:Body> </soap12:Envelope>
    HTTP POST
    POST /WS.asmx/GetDetails HTTP/1.1Host: localhost
    Content-Type: application/x-www-form-urlencoded
    Content-Length: length

    name=string&age=stringHTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length

    <?xml version="1.0" encoding="utf-8"?> <string xmlns="http://tempuri.org/">string</string>
    Quando clicco sul test di HelloWord mi da errore che non trova la pagina ma l'indirizzo è giusto http://localhost:4587/WS.asmx/HelloWorld . Solo una cosa avevo già utilizzato ed utilizzato le asmx tramite codice, con jquery dovrebbe puntarle direttamente giusto?
    Grazie ancora.
    Riccardo Rossi - Smart Agent 3

    GENIALTEK il tuo sito presto e bene
    www.genialtek.it

  5. #5
    Moderatore di ASP.net L'avatar di djciko
    Registrato dal
    Nov 2002
    Messaggi
    6,886
    http://localhost:4587/WS.asmx?wsdl

    ti fa vedere il wsdl ?


    prova prima a consumarlo lato server...

  6. #6
    Utente di HTML.it L'avatar di supermac
    Registrato dal
    Jun 2001
    Messaggi
    1,857
    Io ho avuto lo stesso problema su un server di sviluppo e per farlo andare ho dovuto reinstallare il Framework 4 sull'IIS (si fa con un'istruzione da shell se non ricordo male).
    Non da nessun errore (forse su FireBug ti segnala qualcosa ma non ne sono neanche sicuro), di fatto la chiamata all'asmx non parte.
    Dopo il reinstall è andato tutto come un orologio svizzero.
    Se serve ti cerco l'istruzione (ammesso che tu abbia accesso al webserver).
    W la Ferari effetrenavenave!
    il computer è un somaro veloce! (neanche tanto ndr)

  7. #7
    Utente di HTML.it L'avatar di supermac
    Registrato dal
    Jun 2001
    Messaggi
    1,857
    cià:
    C:\Windows\Microsoft.NET\Framework64\v4.0.30319\as pnet_regiis.exe -i
    Non chiedermi perchè, il codice della mia asmx era tutto giusto ma ha iniziato a funzionare solo dopo che ho lanciato questa istruzione
    W la Ferari effetrenavenave!
    il computer è un somaro veloce! (neanche tanto ndr)

  8. #8
    Grazie ad entrambi,
    dunque chiamando la pagina con ?wsdl mi visualizza xml :

    <?xml version="1.0" encoding="UTF-8"?>

    <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://tempuri.org/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://tempuri.org/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/">




    <wsdl:types>




    <s:schema targetNamespace="http://tempuri.org/" elementFormDefault="qualified">




    <s:element name="HelloWorld">


    <s:complexType/>


    </s:element>




    <s:element name="HelloWorldResponse">




    <s:complexType>




    <s:sequence>


    <s:element type="s:string" name="HelloWorldResult" maxOccurs="1" minOccurs="0"/>


    </s:sequence>


    </s:complexType>


    </s:element>




    ---ECC ECC


    </s:complexType>


    </s:element>


    </s:schema>


    </wsdl:types>




    <wsdl:message name="HelloWorldSoapIn">


    <wsdlart name="parameters" element="tns:HelloWorld"/>


    </wsdl:message>




    <wsdl:message name="HelloWorldSoapOut">


    <wsdlart name="parameters" element="tns:HelloWorldResponse"/>


    </wsdl:message>










    <wsdlortType name="WSSoap">




    <wsdlperation name="HelloWorld">


    <wsdl:input message="tns:HelloWorldSoapIn"/>


    <wsdlutput message="tns:HelloWorldSoapOut"/>


    </wsdlperation>






    -<wsdl:binding type="tns:WSSoap" name="WSSoap12">


    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>




    -<wsdlperation name="HelloWorld">


    <soap12peration style="document" soapAction="http://tempuri.org/HelloWorld"/>




    -<wsdl:input>


    <soap12:body use="literal"/>


    </wsdl:input>




    -<wsdlutput>


    <soap12:body use="literal"/>


    </wsdlutput>


    </wsdlperation>








    -<wsdlort name="WSSoap12" binding="tns:WSSoap12">


    <soap12:address location="http://localhost:4587/WS.asmx"/>


    </wsdlort>


    </wsdl:service>


    </wsdl:definitions>
    Ho provato anche lanciando aspnet_regiis.exe -i ma niente.

    Quello che funziona invece è da codice aspx:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim x As New WS
    MsgBox(x.HelloWorld())



    End Sub

    e questo mi fa incavolare .... sto facendo intanto tutte le prove, inserirò nella pagina i link di jquery ecc in modo da forzarlo ad usare quelle da me indicate
    Riccardo Rossi - Smart Agent 3

    GENIALTEK il tuo sito presto e bene
    www.genialtek.it

  9. #9
    Risolto con :

    <script src="Scripts/jquery-3.1.1.min.js"></script>


    <div>
    <br />
    sotto
    </div>

    <div>
    <input type="button" id="Hello" value="HelloWorld" />

    <br />

    </div>
    <script type="text/javascript">





    $('#Hello').click(function () {


    alert("primo");
    $.ajax({

    type: 'POST',
    url: 'http://localhost:2682/WS.asmx/HelloWorld',
    dataType: "xml",
    data: "{}",
    contentType: "application/xml; charset=utf-8",
    success: function (data) {
    edata = $(data).find("string").text();
    alert(edata);
    },
    error: function () {
    alert("Error:");
    }
    });
    });



    </script>
    Riccardo Rossi - Smart Agent 3

    GENIALTEK il tuo sito presto e bene
    www.genialtek.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.