междоменный вызов с jQuery jsonp для веб-службы ASP.NET

Моя проблема известна и обсуждается здесь и здесь . Но даже после прочтения и реализации предложенных решений я не могу выполнить эту работу.

Проблема : веб-служба, возвращающая xml с добавлением json:


"Now i am getting jsop string""2nd param"

Теперь давайте разбиваем код на разделы:

УДАЛЕННЫЙ СЕРВЕР (IIS 7.0, .NET 4):
web.config :



        
            
                
            
        
    
        
            
                
            
        
    
    
        
        
        
            
                
                
            
        
    


веб-сервис:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using JsonHttpModule;
/// 
/// Summary description for JSONP_EndPoint
/// 
[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 MyService : System.Web.Services.WebService {
    [WebMethod]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public string Sum(string x, string y)
    {
        return x + y;
    }

}


класс HttpModule:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Text;

/// 
/// Summary description for ContentTypeHttpModule
/// 
namespace JsonHttpModule
{
    public class JsonHttpModule : IHttpModule
    {
        private const string JSON_CONTENT_TYPE = "application/json; charset=utf-8";

        public void Dispose()
        {
        }
        public void Init(HttpApplication app)
        {
            app.BeginRequest += OnBeginRequest;
            app.EndRequest += new EventHandler(OnEndRequest);
        }
        public void OnBeginRequest(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;
            HttpRequest request = app.Request;
            //Make sure we only apply to our Web Service
            if (request.Url.AbsolutePath.ToLower().Contains("MyService.asmx"))
            {
                if (string.IsNullOrEmpty(app.Context.Request.ContentType))
                {
                    app.Context.Request.ContentType = JSON_CONTENT_TYPE;
                }
                app.Context.Response.Write(app.Context.Request.Params["callback"] + "(");
            }
        }
        void OnEndRequest(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;
            HttpRequest request = app.Request;
            if (request.Url.AbsolutePath.ToLower().Contains("MyService.asmx"))
            {
                app.Context.Response.Write(")");
            }
        }
    }
}

СТОРОНА КЛИЕНТА (localhost):


    

так что я здесь делаю не так? Вы можете проверить это сами, это живой веб-сервис. Спасибо за помощь.

5
задан baba-dev 16 January 2012 в 18:58
поделиться