두 가지 간단한 방법 (하나는 GET, 다른 POST)으로 VS 2010에서 Restfull WS를 만들었습니다. (Ajax restful WS는 항상 오류가 발생합니다 (피들러는 좋은 응답을 얻습니다)
public class Service1 : IService1
{
public string createUser()
{
return "Successful POST call !!! ";
}
public string loginUser(string email, string password)
{
return "Successful GET call !!! " + email + " - "+ password;
}
}
내가 IIS에이 서비스를 출판 및 브라우저 (만 loginUser (GET) 방법은,는 createUser를 테스트 할 수 없습니다 나의 방법을 테스트 한 :이 방법의
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "createUser")]
string createUser();
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "loginUser/{email}/{password}")]
string loginUser(string email, string password);
}
정의는 간단하다 :처럼 그들은 볼 POST) 메소드) 및 메소드 (loginUser)가 정상적으로 작동합니다. jQuery AJAX로 메서드를 호출하려고 시도 할 때 알림없이 항상 오류가 발생합니다. 내 피들러를 확인하고 올바른 응답이 있습니다.
내 아약스 방법 :
$(document).ready(function(){
$("#button2").click(function(){
$.ajax({
type: "GET",
url: "http://localhost/AutoOglasi/Service1.svc/loginUser/bole/bole",
success: function (response) {
alert("respons "+response);
},
error: function (request, status, error) {
alert(request.responseText+" -- " + status + " --- "+ error);
}
});
});
});
I mozila 불을 지르고 난 섹션 XML 내가 얻을이 :
XML 구문 분석 오류 : MOZ - nullprincipal : 어떤 요소가 위치를 찾을 수 없습니다 {ba25ef4a-f215-486e-b965 -e70714c5af31} 줄 번호 1, 열 1 : ^
내가 여기서 잘못하고있는 것은 피들러가 나에게 좋은 반응을주고 있기 때문에 알아낼 수 없다.
(이미 contenttype : "text/xml"을 추가하려고 시도했습니다.) 다시 시도했습니다. 이제 얻고 있습니다 : "NetworkError : 405 메서드가 허용되지 않습니다 - http : //localhost/AutoOglasi/Service1.svc/loginUser/bole/bole" – Milos
항상 json, xml 또는 html로 contentType을 추가하려고하면 같은 오류가 나타납니다 (위의 오류). 나는 대답의 두 번째 부분을 이해하지 못했다고 생각합니다. bout 상황에서 (ResponseFormat = WebMessageFormat.Xml 포함) 오류가 나타납니다. – Milos
ResponseFormat을 추가하지 않으면 servise가 기본적으로 XML을 제공한다고 생각합니다. 나를 위해 (xml, json, html) 어떤 종류의 응답을 받을지는 중요하지 않습니다. 단지 뭔가를 얻고 싶습니다. – Milos