Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 14700

WebApplication com Webservice

$
0
0
Estou a desenvolver uma aplicação Web no netbeans e preciso de usar um WebService criado em asp.net. Para aceder ao WebService estou a usar uma função jQuery no HTML.
O exemplo da função jQuery e o código HTML que uso é o seguinte:

Código (HTML):
<html>
<head id="Head1" runat="server">
        <title></title>
        <script type="text/javascript" src="jquery-1.3.2.js"></script>

        <script type="text/javascript">
                function serviceCall() {
                        $.ajax({
                                type: "POST",
                                url: 'http://localhost:6335/Service1.asmx?op=TestMethod'
                                data: null,
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                         
                                success: function (msg) {
                                        alert("entrou!");
                                        $("#divResult").html(msg.d);
                                 
                                },
                                error: function (e) {
                                        alert("não deu");
                                        $("#divResult").html("WebSerivce unreachable");
                                }
                        });
                }
         
        </script>
</head>
<body>
        <form id="form1" runat="server">
        <div style="width: 100px; height: 30px; background-color: yellow;" onclick="serviceCall();">
                Click me</div>
         
        <div id="divResult" style="margin-top: 20px;" runat="server">
        </div>
        </form>
</body>
</html>


E o código do WebService:

Código (C#):
namespace WebService1
{
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
         [System.Web.Script.Services.ScriptService]
        public class Service1 : System.Web.Services.WebService

}

Ao executar a aplicação Web o erro que me aparece é o seguinte:
Origin http://localhost:8084 is not allowed by Access-Control-Allow-Origin.

Alguém conhece uma solução que me possa ajudar?

Viewing all articles
Browse latest Browse all 14700