Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Web services 子网站中的sharepoint web服务_Web Services_Sharepoint - Fatal编程技术网

Web services 子网站中的sharepoint web服务

Web services 子网站中的sharepoint web服务,web-services,sharepoint,Web Services,Sharepoint,我正在尝试构建一个对子web上下文敏感的web服务(即,它公开了一个WebMethod,该WebMethod需要能够接触特定子web中的列表) 我已使用以下文件部署了web应用程序: ISAPI/MyService.asmx ISAPI/MyServiceWsdl.aspx ISAPI/MyServiceDisco.aspx 代码隐藏: [WebService] public class MyService : System.Web.Services.WebService { [Web

我正在尝试构建一个对子web上下文敏感的web服务(即,它公开了一个WebMethod,该WebMethod需要能够接触特定子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; }
}
在我的网站集的根网站上,这似乎工作得很好。但是,当我向发出请求并在断点上停止web方法以检查HttpContext时,我发现已向发出请求

我阅读了大量的参考资料,其中描述了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>
<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/" />

在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:

<%@ 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>
<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会导致“未找到”sharepoint错误。换句话说,访问会导致Sharepoint“未找到文件”错误

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


更新:好的,“对象引用未设置…”消息是我犯了一个愚蠢的错误。现在似乎一切正常,除了SPContext.Current.HttpRequestContext.Request.Path属性始终显示根站点下服务的url,而不是当前站点。我使用Wireshark确保客户端发布到正确的url(它是:),我使用ASP.NET跟踪工具,没有发现任何错误(请求以正确的url显示在跟踪中),我使用IIS跟踪实用程序(logman.exe),它没有显示任何意外情况。唯一似乎不正确的事情是,一旦我在服务中遇到断点,HttpRequest上下文

我觉得你的东西不错。我已经用过好几次了,没有问题

我注意到的一个区别是,我获取SPWeb的代码略有不同(而且更简单):


杜德。。。我对SharePoint的各个部分已经有了足够多的类似问题,我完全相信它仍然是一个测试版产品

终于,我发现使用SPContext而不是SPControl来获取当前的web可以满足我的需要。所有MSDN文档都说,要获得这样的Web:

SPControl.GetContextWeb(this.Context);
而且,如果您分解内置web服务,您会发现这也是内置web服务获取当前web服务的方式。就我的服务而言,它不起作用,这确实:

SPContext.Current.Site.OpenWeb();

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

你一定遇到过一些过时的文档。MS在这方面做得并不好。博客是SharePoint最佳实践的最佳来源。