2012-08-25 2 views
1

나는 http://localhost/Test/Test.asmx?op=HelloWorld호출 ASMX 웹 서비스 방법은

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Services; 

namespace TestWebService 
{ 
    [WebService(Namespace = "http://tempuri.org/")] 
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
    [System.ComponentModel.ToolboxItem(false)] 
    [System.Web.Script.Services.ScriptService] 
    public class Test : System.Web.Services.WebService 
    { 
     [WebMethod] 
     public static string HelloWorld() 
     { 
      return "Hello World"; 
     } 

    } 
} 

I 버튼을 호출 클릭 IIS 7.5에서 간단한 ASMX 웹 서비스와 웹 애플리케이션을 호스팅 한 그것을 잘 작동하지만 난으로이 메소드를 호출 할 때 ASP.NET 개발 서버 (http://localhost:1756/HTMLPage1.htm)에서 실행중인 다른 웹 응용 프로그램 프로젝트에서 $ .ajax()를 사용하여 response.status를 0으로 가져오고 웹 메서드를 호출 할 수 없으며 여기에 내 코드가 있습니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>Consume Test </title> 
    <script src="jquery-1.5.1.js" type="text/javascript"></script> 
    <script type="text/javascript"> 

     function displayMessageCall() { 

      $.ajax({ 
       type: "POST", 
       url: "http://localhost/Test/Test.asmx/HelloWorld", 
       data: '{}', 
       contentType: "application/json; charset=utf-8", 
       dataType: "json", 
       success: successMsg, 
       error: errorMsg 

      }); 
     } 

     function successMsg(response) { 
      alert('Success'); 
     } 

     function errorMsg(response) { 
      alert(response.status + " " + response.statusText) 
     } 

     $(document).ready(function() { 
      displayMessageCall(); 
     }); 
    </script> 
</head> 
<body> 
</body> 
</html> 

나는 뭔가가 부족합니까?

+0

easyXDM을 사용하여이 문제를 해결할 수있는 방법을 찾았습니다. http://easyxdm.net/wp/2010/03/17/setting-up-your-first-socket/ – ddfnfal

답변

0

나는 당신이 단지 same origin policy에 달하고 있다고 생각합니다.

포트가 다르기 때문에 브라우저가 자바 스크립트가 웹 서비스에 도달하지 못하도록 제한하고 있습니다. 물론 workarounds도 있습니다.

+0

안녕하세요. 해결 방법과 나는 어쨌든 도와 주셔서 감사합니다 내 문제에 대한 또 다른 해결책을 찾았습니다 ... – ddfnfal