首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >webservice oneway和新SPSite(myUrl)

webservice oneway和新SPSite(myUrl)
EN

Stack Overflow用户
提问于 2008-12-04 10:42:20
回答 3查看 2.1K关注 0票数 1

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

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

代码语言:javascript
复制
[SoapDocumentMethod(OneWay = true)]
        [WebMethod(Description = "TestOneWay")]
        public voidTestOneWay(string webUrl)
        {
            using (SPSite site = new SPSite(webUrl))
            {
                 ....
            }
         }

例外情况是:

代码语言:javascript
复制
[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)
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2008-12-10 10:28:01

我已经找到了一个解决方法来解决我的problem.Create新HttpContext。现在的问题是:这是正确的解决方案,还是有我不考虑的影响?

我用来改变上下文的方法是:

代码语言:javascript
复制
//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;
        }
票数 1
EN

Stack Overflow用户

发布于 2008-12-24 19:30:09

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

Well..duh :)

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

票数 0
EN

Stack Overflow用户

发布于 2009-10-27 19:22:43

使用此命令将对您有效:

代码语言:javascript
复制
SPWeb web = SPContext.Current.Web
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/340192

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档