C# 使用不同主机头的ASMX Javascript代理
我正在我的应用程序中使用ASMX服务,希望它指向特定的web服务URL 我将其定义如下:C# 使用不同主机头的ASMX Javascript代理,c#,.net,web-services,sharepoint,asmx,C#,.net,Web Services,Sharepoint,Asmx,我正在我的应用程序中使用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 Service
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
});
在我看来,您指定了服务器相对路径。尝试使用并解析如下路径:
~site/_vti_bin/MyService.asmx
在SPUtility类中,有一个函数,用于解析带有前缀“~site”(解析为当前SPWeb url)和“~sitecollection”(解析为当前SPSite url)的前缀路径
此处“当前”表示SPSite的SPContext.current.Site和SPWeb的SPContext.current.Web。我不知道这是否是您出现问题的原因,但我相信您可能指向了asmx的错误位置。“\u vti\u bin”文件夹是frontpage extensions创建的文件夹。asmx文件应位于网站的根目录或网站根目录中的文件夹结构中。它不应该位于bin或“\u vti\u bin”中。@Alex Mendez:所有SharePoint服务都位于\u vti\u bin中。我从未使用过SharePoint,所以我不知道这一点。谢谢你的信息。现在,我想不出还有什么别的了。