我有简单的.NET Web服务,并尝试将其称为Java Script:
<html>
<head>
<title></title>
</head>
<body>
<script src="jquery-2.1.4.min.js"></script>
<script>
function ss() {
var webserUrl = "http://localhost/WebService.asmx";
var soapRequest =
'<?xml version="1.0" encoding="utf-8"?> \
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<Add xmlns="http://tempuri.org/"> \
<x>int</x> \
<y>int</y> \
</Add> \
</soap:Body> \
</soap:Envelope>';
$.ajax({
type: "POST",
url: webserUrl,
contentType: "text/xml",
crossDomain: true,
dataType: "xml",
data: soapRequest,
success: SuccessOccur,
error: ErrorOccur
});
};
function SuccessOccur(data, status, req) {
if (status == "success")
alert("OK "+req.responseText);
}
function ErrorOccur(data, status, req) {
alert("ERR "+req.responseText + " " + status);
}
</script>
<form>
<input type="button" value="Click here" onclick="ss()">
</form>
</body>
</html>
服务:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public int Add(int x, int y)
{
return x+y;
}
}
的web.config:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
我应该在哪里寻找问题 - 服务器端还是客户端?
如果服务器端我应该寻找问题?日志文件C:\inetpub\logs\LogFiles
看起来并不是很有用。