Web services webservice单向和新SPSite(myUrl)

Web services webservice单向和新SPSite(myUrl),web-services,sharepoint,moss,Web Services,Sharepoint,Moss,我对打开moss站点的单向web方法有问题(可能是因为在单向web方法中上下文为null) 是否可以重写此代码以删除空引用异常?(没有单向属性,我没有例外) 例外情况是: [2304] Error:Object reference not set to an instance of an object. [2304] w3wp.exe Error: 0 : [2304StackTrace: at System.Web.Hosting.ISAPIWorkerRequestInProc.GetA

我对打开moss站点的单向web方法有问题(可能是因为在单向web方法中上下文为null)

是否可以重写此代码以删除空引用异常?(没有单向属性,我没有例外)

例外情况是:

[2304] Error:Object reference not set to an instance of an object.
[2304] w3wp.exe Error: 0 :
[2304StackTrace:   at System.Web.Hosting.ISAPIWorkerRequestInProc.GetAdditionalServerVar(Int32 index)
[2304]    at System.Web.Hosting.ISAPIWorkerRequestInProc.GetServerVariable(String name)
[2304]    at System.Web.HttpRequest.AddServerVariableToCollection(String name)
[2304]    at System.Web.HttpRequest.FillInServerVariablesCollection()
[2304]    at System.Web.HttpServerVarsCollection.Populate()
[2304]    at System.Web.HttpServerVarsCollection.Get(String name)
[2304]    at System.Collections.Specialized.NameValueCollection.get_Item(String name)
[2304]    at Microsoft.SharePoint.SPGlobal.CreateSPRequestAndSetIdentity(Boolean bNotGlobalAdminCode, String strUrl, Boolean bNotAddToContext, Byte[] UserToken, String userName, Boolean bIgnoreTokenTimeout, Boolean bAsAnonymous)
[2304]    at Microsoft.SharePoint.SPRequestManager.GetContextRequest(SPRequestAuthenticationMode authenticationMode)
[2304]    at Microsoft.SharePoint.Administration.SPFarm.get_RequestNoAuth()
[2304]    at Microsoft.SharePoint.SPSite.CopyUserToken(SPUserToken userToken)
[2304]    at Microsoft.SharePoint.SPSite.SPSiteConstructor(SPFarm farm, Guid applicationId, Guid contentDatabaseId, Guid siteId, SPUrlZone zone, Uri requestUri, String serverRelativeUrl, Boolean hostHeaderIsSiteName, Uri redirectUri, Pairing pairing, SPUserToken userToken)
[2304]    at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)
[2304]    at Microsoft.SharePoint.SPSite..ctor(String requestUrl)
[2304]    at Reply.Moss2EAI.SPHandler.GetAllFlowConfiguration(String webUrl, String flowConList)
[2304]    at Reply.Moss2EAI.EaiMossIntegration.GetMessagesFromEai(String webUrl, String listName, String applicationName)

我找到了解决问题的方法。创建新的HttpContext。现在的问题是: 这是正确的解决方案,还是我没有考虑到的暗示?

我用于更改上下文的方法如下:

//Call this before call new SPSite()
 private static void ChangeContext(string webUrl)
        {
            Trace.TraceInformation("ChangeContext");
            HttpContext current = HttpContext.Current;
            HttpRequest request = new HttpRequest("", webUrl, "");
            HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter(CultureInfo.CurrentCulture)));
            HttpContext.Current.User = current.User;
        }

我找到了解决问题的方法。创建新的HttpContext。现在的问题是: 这是正确的解决方案,还是我没有考虑到的暗示?

我用于更改上下文的方法如下:

//Call this before call new SPSite()
 private static void ChangeContext(string webUrl)
        {
            Trace.TraceInformation("ChangeContext");
            HttpContext current = HttpContext.Current;
            HttpRequest request = new HttpRequest("", webUrl, "");
            HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter(CultureInfo.CurrentCulture)));
            HttpContext.Current.User = current.User;
        }

我看到的唯一含义是您实际上正在使用一个新的HttpContext

嗯……嗯:)


无论如何,如果您还设置了输入和输出过滤器,这将产生影响。例如,如果您将WebServiceExtensions(WSE)与您自己的输入和输出过滤器一起使用。在这种情况下,您应该将数据存储在HttpContext中(在输入和输出过滤器中),并使用该上下文。这样您就可以只使用一个httpContext,而不是创建第二个httpContext,并防止在扩展软件时出现任何错误

我看到的唯一含义是您实际上正在使用一个新的HttpContext

嗯……嗯:)


无论如何,如果您还设置了输入和输出过滤器,这将产生影响。例如,如果您将WebServiceExtensions(WSE)与您自己的输入和输出过滤器一起使用。在这种情况下,您应该将数据存储在HttpContext中(在输入和输出过滤器中),并使用该上下文。这样您就可以只使用一个httpContext,而不是创建第二个httpContext,并防止在扩展软件时出现任何错误

使用此选项将对您有效:

SPWeb web = SPContext.Current.Web

使用此选项将对您有效:

SPWeb web = SPContext.Current.Web