2012-09-03 2 views
1

나는 웹 서비스를 만들었습니다. Ajax jQuery를 사용하여이 웹 서비스에 액세스하려고합니다. 동일한 도메인에서 액세스 할 수 있습니다. 하지만 다른 도메인에서이 웹 서비스에 액세스하려고합니다.크로스 도메인 asp.net 웹 서비스를 만드는 방법

누구든지 asp.net에서 상호 도메인 웹 서비스를 만드는 방법을 알고 있습니까? 다른 도메인에서 액세스 할 수 있도록 web.config 파일의 모든 설정?

내 웹 서비스

[WebService(Namespace = "http://tempuri.org/")] 
[System.Web.Script.Services.ScriptService] 
public class Service : System.Web.Services.WebService 
{ 
    public Service() { 
    } 

    [WebMethod] 
    public string SetName(string name) { 
     return "hello my dear friend " + name; 

    } 
} 

자바 스크립트

$.ajax({ 
    type: "GET", 
    url:'http://192.168.1.119/Service/SetName.asmx?name=pr', 
    ContentType: "application/x-www-form-urlencoded", 
    cache: false, 
    dataType: "jsonp", 
    success: onSuccess 
}); 
+1

이 스레드를 따라 가십시오 http://stackoverflow.com/questions/861784/how-to-call-a-web-service-from-jquery –

+0

또한 http://stackoverflow.com/questions/230401/how를 사용할 수 있습니다. 사용하기 jquery-to-call-asp-net-web-service –

답변

0

nuget를 설치 한 후 다음이 시도는 nuget 갤러리에 Json.Net의 링크입니다 : nuget.org/packages/Newtonsoft. Json

using Json; 
using Newtonsoft.Json; 
using System.Xml.Serialization; 


    [WebService(Namespace = "http://tempuri.org/")] 
     [System.Web.Script.Services.ScriptService] 
     public class Service : System.Web.Services.WebService 
     { 
      public Service() { 
      } 

      [WebMethod] 
     [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
      public string SetName(string name) { 
     return JsonConvert.SerializeObject("hello my dear friend " + name, Newtonsoft.Json.Formatting.Indented); 

      } 
     } 
관련 문제