C# Sharepoint使用Web服务
在服务器上安装wss 3.0(我想是Sharepoint 2007)时,调用默认安装的asmx Web服务时遇到一些问题 我们的sharepoint正在使用表单身份验证。 在IIS中,我可以看到网站,并且在该网站中存在虚拟目录“\u vti\u bin”(这是Web服务所在的位置) 我可以毫无问题地浏览WSDL,因此我可以将其添加到VisualStudio解决方案中的web引用中(我使用“web引用”而不是“服务引用”方法将引用添加到我的解决方案)。 我无法浏览到ASMXWebService本身,它一直重定向到登录页面 在我的代码中,我尝试使用身份验证asmx服务,但似乎无法正确使用它 这是我的代码:C# Sharepoint使用Web服务,c#,asp.net,web-services,sharepoint,C#,Asp.net,Web Services,Sharepoint,在服务器上安装wss 3.0(我想是Sharepoint 2007)时,调用默认安装的asmx Web服务时遇到一些问题 我们的sharepoint正在使用表单身份验证。 在IIS中,我可以看到网站,并且在该网站中存在虚拟目录“\u vti\u bin”(这是Web服务所在的位置) 我可以毫无问题地浏览WSDL,因此我可以将其添加到VisualStudio解决方案中的web引用中(我使用“web引用”而不是“服务引用”方法将引用添加到我的解决方案)。 我无法浏览到ASMXWebService本身
protected Cookie _authCookie;
CookieContainer _cookieContainer;
using (Authentication spAuthentication = new Authentication())
{
spAuthentication.Url = "https://sharepointserverxx.com/_vti_bin/Authentication.asmx";
spAuthentication.CookieContainer = new CookieContainer();
//spAuthentication.AllowAutoRedirect = true;
spAuthentication.PreAuthenticate = true;
LoginResult loginResult = spAuthentication.Login(txtUser.Text, txtPassword.Text);
_authCookie = new Cookie();
if (loginResult.ErrorCode == LoginErrorCode.NoError)
{
CookieCollection cookies = spAuthentication.CookieContainer.GetCookies(new Uri(spAuthentication.Url));
_authCookie = cookies[loginResult.CookieName];
_cookieContainer = new CookieContainer();
_cookieContainer.Add(_authCookie);
return true;
}
else
txtResult.Text = "Invalid Username/Password while authenticating to the sharepoint webservices.";
return false;
}
我在线路上遇到以下错误,代码如下:
LoginResult loginResult = spAuthentication.Login(txtUser.Text, txtPassword.Text);
错误:请求失败,错误消息为:
对象移动到我很确定您的问题是由于to _vti_bin需要与当前服务器和网站集相关 这是我在类构造函数中调用的代码,用于设置我需要的所有服务
// Server URL is the root server E.G.
// I set mine in class constructor
String serverUrl = "http://192.168.100.10:1234/";
/// <summary>
/// Web referenced must be relative to the site collection you are seeking to query
/// </summary>
/// <param name="siteCollectionUrl"></param>
private void SetWebReferencePaths(string siteCollectionUrl)
{
string siteUrl = serverUrl;
if (!siteUrl.EndsWith("/"))
siteUrl += "/";
if (!siteCollectionUrl.EndsWith("/"))
siteCollectionUrl += "/";
string fullPath = "";
if (siteUrl != siteCollectionUrl)
{
fullPath = siteUrl + siteCollectionUrl;
}
else
{
fullPath = siteUrl;
}
listServiceUrl = fullPath + "_vti_bin/Lists.asmx";
groupsServiceUrl = fullPath + "_vti_bin/UserGroup.asmx";
permissionsServiceUrl = fullPath + "_vti_bin/Permissions.asmx";
siteDataServiceUrl = fullPath + "_vti_bin/SiteData.asmx";
websServiceUrl = fullPath + "_vti_bin/Webs.asmx";
listServiceUrl = fullPath + "_vti_bin/Lists.asmx";
groupsServiceUrl = fullPath + "_vti_bin/UserGroup.asmx";
permissionsServiceUrl = fullPath + "_vti_bin/Permissions.asmx";
siteDataServiceUrl = fullPath + "_vti_bin/SiteData.asmx";
websServiceUrl = fullPath + "_vti_bin/Webs.asmx";
// result would look like
// http://sharep2007/SiteDirectory/FirstSite/_vti_bin/Lists.asmx
// It's broken down like this
// http://sharep2007/ + SiteDirectory/FirstSite/ + _vti_bin/Lists.asmx
// serverURL + siteCollectionURL + _vti_bin/Lists.asmx
}
您收到的错误可能有多种原因。您应该在Sharepoint中启用详细日志记录(在管理中心=>Operations中),以查看确切的错误 你在用IIS7吗?在经典模式下,IIS7上的asmx处理程序存在一些兼容性问题。能否尝试在sharepoint网站的Web.Config中添加缺少的HttpHandler
<system.web><httpHandlers>
<remove verb="*" path="*.asmx" />
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />
<add verb="*" path="_vti_bin/ReportServer" type="Microsoft.ReportingServices.SharePoint.Soap.RSProxyHttpHandler, RSSharePointSoapProxy, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
<add verb="*" path="Reserved.ReportViewerWebPart.axd" type="Microsoft.ReportingServices.SharePoint.UI.WebParts.WebPartHttpHandler, Microsoft.ReportingServices.SharePoint.UI.WebParts, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</httpHandlers></system.web>
您好,我认为我们的sharepoint除了根网站之外没有其他网站/集合。。我怎么能肯定呢?Thx.您好,我认为除了根网站之外,我们的sharepoint没有其他网站/集合。。我怎么能确定呢?Thx。@Rise\u你可以从你的酒吧里的URL来判断。我刚刚在我的根sharepoint站点上创建了一个新站点,它看起来像这样http://sharep2007/SiteDirectory/FirstSite/default.aspx
因此,定位其Web服务需要此URLhttp://sharep2007/SiteDirectory/FirstSite/_vti_bin/Lists.asmx
您至少应该有用户站点(当您登录并单击“MySite”按钮)例如http://sharep2007/personal/myusername/
您还可以创建自己的自定义命名集合,例如http://sharep2007/MyTestCollection/MySiteName
Hi,我只有根站点,没有子站点。我刚刚创建了一个名为“Test”的新子站点,并将webservice调用更改为““,但我有同样的错误。@Rise\u你能在浏览器中导航到URL吗?(并查看列出的web服务方法)您好,这正是问题所在:)我在sharepoint web.config的httpHandlers中添加了*.asmx条目,这些web服务工作得很好:)谢谢!
using (ShareLists.Lists listService = new Lists())
{
listService.Url = listServiceUrl;
// Code using service
}
<system.web><httpHandlers>
<remove verb="*" path="*.asmx" />
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />
<add verb="*" path="_vti_bin/ReportServer" type="Microsoft.ReportingServices.SharePoint.Soap.RSProxyHttpHandler, RSSharePointSoapProxy, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
<add verb="*" path="Reserved.ReportViewerWebPart.axd" type="Microsoft.ReportingServices.SharePoint.UI.WebParts.WebPartHttpHandler, Microsoft.ReportingServices.SharePoint.UI.WebParts, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</httpHandlers></system.web>