ASMX Javascript proxy using different host headers
I am using an ASMX service in my app and would like it to point to a particular web service URL.
I have defined it as below:
string serviceUrl = SPContext.Current.Web.Url + "/_vti_bin/MyService.asmx";
ScriptManager scriptManager = ScriptManager.GetCurrent(Page);
if (scriptManager != null) scriptManager.Services.Add(new ServiceReference(serviceUrl));
else
{
scriptManager = new ScriptManager();
scriptManager.Services.Add(new ServiceReference(serviceUrl));
Page.Form.Controls.Add(scriptManager);
}
Here SPContext.Current.Web.Url ==> http://mysite/mysubsite
But when I invoke the service from Javascript like below, host header inspection in the Firebug suggests that the Javascript proxy is actually calling the service at: http://mysite/_vti_bin/MyService.asmx/Execute
MyWorkCore.API.Execute("GetData", dataXml, function (response) {
// doing something he开发者_如何转开发re
});
You specified server relative path, as I see it. Try using and resolving the path like this:
~site/_vti_bin/MyService.asmx
In SPUtility class there a function that resolves such prefixed paths with prefixes "~site" (resolved to current SPWeb url) and "~sitecollection" that resolved to current SPSite URL.
Here "current" means SPContext.Current.Site for SPSite and SPContext.Current.Web for SPWeb.
精彩评论