【问题标题】:ASMX Javascript proxy using different host headers使用不同主机头的 ASMX Javascript 代理
【发布时间】:2011-06-28 17:28:28
【问题描述】:

我在我的应用程序中使用 ASMX 服务,并希望它指向特定的 Web 服务 URL。

我定义如下:

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

【问题讨论】:

  • 我不知道这是否是您的问题的原因,但我相信您可能指向错误的 asmx 位置。 “_vti_bin”文件夹是frontpage 扩展创建的文件夹。 asmx 文件应位于站点的根目录或网站根目录内的文件夹结构中。它不应驻留在 bin 或“_vti_bin”中。
  • @Alex Mendez:所有 SharePoint 服务都驻留在 _vti_bin 中
  • 我从未使用过sharepoint,所以不知道这一点。谢谢(你的)信息。此刻,我想不出别的了。

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


【解决方案1】:

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

~site/_vti_bin/MyService.asmx

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

这里的“当前”是指 SPSite 的 SPContext.Current.Site 和 SPWeb 的 SPContext.Current.Web。

【讨论】:

    猜你喜欢
    • 2012-03-08
    • 2018-09-17
    • 2019-04-02
    • 2019-10-12
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 1970-01-01
    • 2012-12-30
    相关资源
    最近更新 更多