读书人

: WEB Infopath 调用sharepooint自开放

发布时间: 2013-10-11 14:52:39 作者: rapoo

紧急求助: WEB Infopath 调用sharepooint自开放web service问题
我在sharepoint 2013 server中(但继续用sharepoint 2010模式)自定义开放了一个webservice, 里面有两个简单演示webmethod,

[WebMethod]
public string TestString(string inputstring)
{
return inputstring + " -- get it";
}

public string GetSiteListCount()
{
var web = SPContext.Current.Web;
return web.Title;
}

该webservice 发布到我的sharepoint server上,deploy 路径是 {SharePointRoot}\Template\Layouts\WebServiceDemo\,我再创建一个 console 程序测试引用该webservice(引用路劲是 http://mysharepoint/_layouts/WebServiceDemo/MyCustomWebService.asmx
都能正常使用这两个 WebMethod(上面都是在该服务器上测试);

我的目的是要在web infopath form上应用, 在infopath vsta中, 仿照console的方式引用及调用它们, 把infopath form 发布到服务器上后测试, 第一个webmethod能正常调用,而第二个则在infopath 开启时出错; 我也怀疑是是否是权限问题, 把调用时用的认证
System.Net.CredentialCache.DefaultCredentials 更改为
new NetworkCredential("domain\administrator", "password")还是不行

请各路大侠协助,谢谢!




web?service sharepoint infopath
[解决办法]
namespace WebService1
{
/// <summary>
/// Service1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
int ii = 0;
[WebMethod]
public string HelloWorld()
{
string getRe = "TEST";
try
{

SPSecurity.RunWithElevatedPrivileges(delegate() //虚拟管理员,否则其他用户访问没有权限
{
using (SPSite site = new SPSite("http://tc-demo"))
{
using (SPWeb web = site.OpenWeb("expense"))
{
SPList list = web.Lists["WebStart"];

foreach (SPListItem item in list.Items)
{
//允许编辑
site.AllowUnsafeUpdates = true;
web.AllowUnsafeUpdates = true;


//
SPWorkflowAssociationCollection wfAssociationColls = list.WorkflowAssociations;
CultureInfo ci = CultureInfo.CurrentCulture;
SPWorkflowAssociation spWFAss =
wfAssociationColls.GetAssociationByName("webStart", ci);
string data = spWFAss.AssociationData;

if (item.HasRunningWorkflow() == false)
{
//窗体程序
//web.Site.WorkflowManager.StartWorkflow(item, spWFAss, spWFAss.AssociationData, true);
//控制台程序
site.WorkflowManager.StartWorkflow(item, spWFAss, data, true);
ii = ii + 1;
}

}
getRe += ii;
}
}
}
);
}

catch (Exception ex)
{
getRe = ex.ToString();
}
//}
return getRe;
}
}
}

读书人网 >行业软件

热点推荐