2009-05-05 59 views
2

我正在尝试构建一个对子网上下文敏感的Web服务(即,它公开了需要能够在特定子站点中触摸列表的WebMethod)。sharepoint web服务在子站

我已经部署了Web应用程序与下列文件:

ISAPI/MyService.asmx 
ISAPI/MyServiceWsdl.aspx 
ISAPI/MyServiceDisco.aspx 

代码隐藏:

[WebService] 
public class MyService : System.Web.Services.WebService 
{ 
    [WebMethod] 
    public ListSettings GetListSettings(string listName) 
    { 
     SPWeb site = SPControl.GetContextWeb(this.Context); 
     SPList list = site.Lists[listName]; 

     return new ListSettings(list); 
    } 

    [WebMethod] 
    public void UpdateListSettings(string listName, ListSettings settings) 
    { 
     SPWeb site = SPControl.GetContextWeb(this.Context); 
     SPList list = site.Lists[listName]; 

     list.EnableFolderCreation = settings.EnableFolders; 
     list.Update(); 
    } 
} 

public class ListSettings 
{ 
    public ListSettings() { } 

    internal ListSettings(SPList list) 
    { 
     EnableFolders = list.EnableFolderCreation; 
    } 

    public bool EnableFolders { get; set; } 
} 

这似乎在我的网站集的根网站工作得很好。但是,当我向http://moss/subweb/_vti_bin/MyService.asmx发出请求,并停止断点上的Web方法来检查HttpContext时,我发现请求已被作出http://moss/_vti_bin/MyService.asmx

我读了一些描述WSDL/disco文件和ISAPI中的spdisco.aspx文件中所需的调整的资源,并做出了我虽然应该做出的调整。像这样:

在MyServiceDisco.aspx:

<%@ Page Inherits="System.Web.UI.Page" Language="C#" %> 
<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Import Namespace="Microsoft.SharePoint.Utilities" %> 
<%@ Import Namespace="Microsoft.SharePoint" %> 
<% Response.ContentType = "text/xml"; %> 

<discovery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/disco/"> 
    <contractRef ref=<% SPEncode.WriteHtmlEncodeWithQuote(Response, SPWeb.OriginalBaseUrl(Request) + "?wsdl", '"'); %> 
      docRef=<% SPEncode.WriteHtmlEncodeWithQuote(Response, SPWeb.OriginalBaseUrl(Request), '"'); %> 
      xmlns="http://schemas.xmlsoap.org/disco/scl/" /> 
    <soap address=<% SPEncode.WriteHtmlEncodeWithQuote(Response, SPWeb.OriginalBaseUrl(Request), '"'); %> 
     xmlns:q1="http://tempuri.org/" binding="q1:MyServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" /> 
    <soap address=<% SPEncode.WriteHtmlEncodeWithQuote(Response, SPWeb.OriginalBaseUrl(Request), '"'); %> 
     xmlns:q2="http://tempuri.org/" binding="q2:MyServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" /> 
</discovery> 

在MyServiceWsdl.aspx的顶部:

<%@ Page Inherits="System.Web.UI.Page" Language="C#" %> 
<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Import Namespace="Microsoft.SharePoint.Utilities" %> 
<%@ Import Namespace="Microsoft.SharePoint" %> 
<% Response.ContentType = "text/xml"; %> 

,并在底部:

<wsdl:service name="MyService"> 
    <wsdl:port name="MyServiceSoap" binding="tns:MyServiceSoap"> 
     <soap:address location=<% SPEncode.WriteHtmlEncodeWithQuote(Response, SPWeb.OriginalBaseUrl(Request), '"'); %> /> 
    </wsdl:port> 
    <wsdl:port name="MyServiceSoap12" binding="tns:MyServiceSoap12"> 
     <soap12:address location=<% SPEncode.WriteHtmlEncodeWithQuote(Response, SPWeb.OriginalBaseUrl(Request), '"'); %> /> 
    </wsdl:port> 
    </wsdl:service> 

最后, spdisco.aspx的新增功能:

<contractRef ref=<% SPEncode.WriteHtmlEncodeWithQuote(Response, spWeb.Url + "/_vti_bin/MyService.asmx?wsdl", '"'); %> 
      docRef=<% SPEncode.WriteHtmlEncodeWithQuote(Response, spWeb.Url + "/_vti_bin/MyService.asmx", '"'); %> 
      xmlns="http://schemas.xmlsoap.org/disco/scl/" /> 
    <discoveryRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + "/_vti_bin/MyService?disco"),Response.Output); %> 
       xmlns="http://schemas.xmlsoap.org/disco/" /> 

终于,我认为我已经尽了一切努力使服务在网站集中的每个网站都能正常工作,但是,它似乎并不正确。我忘了做什么?

更新:另一个信息小点是,试图获取发现XML导致“未找到”共享点错误。换句话说,访问http://moss/mysubsite/_vti_bin/MyService.asmx?disco会导致Sharepoint“File Not Found”错误。

更新:原因是MyServiceDisco.aspx中存在一个小错字,导致“文件未找到”错误。但是,我解决了这个问题,现在服务已经完全失效。使用WCF测试客户端,我收到一条错误消息:“服务器无法处理请求--->未将对象引用设置为对象的实例”,随后是堆栈跟踪。从我正在处理的应用程序中,当我调用生成的代理类“MyServiceSoapClient”时,响应是“远程服务器返回错误:NotFound”。

Arrrgggh!

更新:好的,“对象引用未设置...”的消息是我头上一个头颅的错误的结果。事情似乎现在正在工作,,除了 SPContext.Current.HttpRequestContext.Request.Path属性总是显示根网站,而不是当前网站下的服务的网址。我使用Wireshark来确保客户端正在POST到正确的URL(它是:http://moss/subweb/_vti_bin/MyService.asmx),我已经使用ASP.NET跟踪工具,并没有发现任何错误(请求显示在跟踪中正确的URL),并且我使用了IIS跟踪实用程序(logman.exe),它没有任何意外的显示。唯一看起来不正确的是当我在服务中触发断点时,HttpRequest上下文。

回答

2

Duuude ......我已经受够了问题,类似这样的各种部件的SharePoint是彻底确信它仍然是一个测试版产品。

终于,我发现使用SPContext而不是SPControl来获取当前的网络给了我我需要的东西。所有MSDN文档说要拿到网络是这样的:

SPControl.GetContextWeb(this.Context); 

而且,如果你拆开内置的Web服务,你会发现,这是怎么也内置Web服务获取当前网页。对于我的服务,它没有工作,而且这是:

SPContext.Current.Site.OpenWeb(); 

为什么????为什么,微软为什么???!

+1

您一定遇到过一些过时的文档。 MS对此并不擅长。博客是SharePoint最佳实践的最佳来源。 – 2009-10-09 08:35:59

1

你对我看起来不错。我以前多次使用过这些,没有任何问题。

一个不同之处,我发现是我用于获取的SPWeb代码略有不同(更简单):

 // Get the current site based on our context 
     // Note that this approach does _not_ require a Dispose of the SPWeb 
     SPWeb site = SPContext.Current.Web; 
+0

你能够在子网站中获得正确的上下文吗? – 2009-05-05 04:28:59

相关问题