ASMX使用不同主机头的Javascript代理

时间:2011-06-28 17:28:28

标签: c# .net web-services sharepoint asmx

我在我的应用中使用ASMX服务,并希望它指向特定的网络服务网址。

我已将其定义如下:

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);
}

此处SPContext.Current.Web.Url ==> http://mysite/mysubsite

但是,当我从下面的Javascript调用服务时,Firebug中的主机头检查表明Javascript代理实际上在以下地址调用服务:http://mysite/_vti_bin/MyService.asmx/Execute

MyWorkCore.API.Execute("GetData", dataXml, function (response) {
    // doing something here
});

1 个答案:

答案 0 :(得分:0)

您指定了服务器相对路径。尝试使用和解析这样的路径:

~site/_vti_bin/MyService.asmx

在SPUtility类中,有一个函数可以解析带有前缀“〜site”(已解析为当前SPWeb url)和“〜sitecollection”的解析为当前SPSite URL的前缀路径。

此处“current”表示SPSite的SPContext.Current.Site和SPWeb的SPContext.Current.Web。