Sharepoint Foundation 2010 사이트의 사용자 정의 webpart에서로드 된 javascript를 통해 AJAX에서 호출 할 수있는 WCF를 설정하려고합니다. Javascript 측에서 처리를 단순화하기 위해 Json에게 호출자에게 다시 제공하는 Restful 서비스를 제시하고자합니다.AJAX를 사용하여 Sharepoint WCF에 액세스 할 때 SPContext.Current null
문제는 내가 AJAX 호출로 서버를 호출 할 때 SPContext.Current가 null이라는 것입니다. 내가 MultipleBaseAddressWebServiceHostFactory을 사용하고
WebService에가의 SVC 파일에서 웹 서비스
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$"%>
<%@ServiceHost Language="C#" Debug="true"
Service="Driftportalen.LvService.SuggestService"
Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
%>
에게 계약을 만들려면 다음과 같이 웹 서비스의
[ServiceContract(Namespace = "", ProtectionLevel= ProtectionLevel.None)]
public interface ISuggestServiceTest
{
[WebGet(UriTemplate = "/SuggestAddress/{streetprefix}/", ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
Dictionary<string, GenericAddress> SuggestAddress(string streetprefix);
}
구현은 기본적이다.
[Guid("BA6733B3-F98D-4AD8-837D-7673F8BC527F")]
[BasicHttpBindingServiceMetadataExchangeEndpoint]
[ServiceBehavior(IncludeExceptionDetailInFaults = true, AddressFilterMode = AddressFilterMode.Any)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class SuggestService : ISuggestServiceTest
{
private SPWeb currentWeb;
public SPWeb CurrentWeb
{
get
{
if (currentWeb == null)
{
var siteUrl = SPContext.Current.Web.Url;
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (var site = new SPSite(siteUrl))
using (var web = site.OpenWeb())
{
currentWeb = web;
}
});
}
return currentWeb;
}
}
public Dictionary<string, GenericAddress> SuggestAddress(string streetprefix)
{
LvService lvService = new LvService(CurrentWeb);
Dictionary<string, GenericAddress> suggestions = new Dictionary<string, GenericAddress>();
//SNIP
//Code that uses lvService to populate suggestions
return suggestions;
}
}
나는 모든 것이 예상대로 작동하는 웹 브라우저에서하고있는 웹 서비스를 호출하면 내가 다시 올바른 데이터를 얻을 수 있음을 확인했습니다.
나는 다음과 같은 아약스는 내가 올바른 URL이 자바 스크립트에서 호출되는 것을 확인하고 난이 올바른 코드가 실제로 도달하는 서버 측에 확인하지만, SPContext 한 방화범을 사용하여
$.ajax({
url: addressUrl + "/"+request.term,
dataType: 'json',
success: function (data) {
responseCallback(data);
$(this).removeClass("fetching");
}
});
전화를 사용합니다. 현재 null입니다.
Sharepoint 서버는 Windows 및 클레임을 사용하여 로그인합니다. 즉, Sharepoint 솔루션과 다른 계정을 사용하여 실제 WCF가 실행되지만 vti_bin 아래 폴더에 배포 할 때 Sharepoint는 해당 컨텍스트를 WCF에 제공해야합니다. 나에게 AJAX 호출이 Sharepoint에서 컨텍스트를 제공하지 못하는 것처럼 보입니다. 어떤면에서는 익명입니다.
은 첫째 나는 자체가 browswer에서 호출 할 때 무작위로 실패 이후 비난했다 웹 서비스를 가정,하지만 난 내가 할 수있는 방법 재단 2010
셰어에 업그레이드를 설치하여이 문제를 정리 생각 셰어 포인트 사이트에 로그인 한 사용자의 컨텍스트에 웹 서비스가 액세스 할 수 있도록 자바 스크립트에서 AJAX 호출을 허용하는 자바 스크립트/웹 서비스의 AJAX 호출?
이것은 내 하루를 저장했습니다! 너 락 : –