您的位置:首页 > 其它

Update SPListItem using Web Service

2007-12-03 14:26 351 查看
这几天为了在SharePoint上集成发短信的功能,忙得不可开交。短信猫的驱动程序Mondem.dll在64跨平台调用的时候出现封装如下:

public class CmonDem

System.BadImageFormatException was unhandled

Message="试图加载格式不正确的程序。 (异常来自 HRESULT:0x8007000B)"

Source="dxmwinapp"

StackTrace:

在 dxmwinapp.CmonDem.fnGetStatus(Int32 nPortNo)

在 dxmwinapp.Form1.timer1_Tick(Object sender, EventArgs e) 位置 E:\短信猫1\短信猫\二次开发包\DLL接口\samples\c#Demo(news)\Form1.cs:行号 446

在 System.Windows.Forms.Timer.OnTick(EventArgs e)

在 System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)

在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)

在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)

在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

在 dxmwinapp.Form1.Main() 位置 E:\短信猫1\短信猫\二次开发包\DLL接口\samples\c#Demo(news)\Form1.cs:行号 349

在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)

在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

在 System.Threading.ThreadHelper.ThreadStart()

查了好久的资料,才弄明天原来是编译的时候出问题了,Mondem.dll驱动是在32位机器上编译的,但是我的程序是编译成64位的,所以平台调用的时候就出错误了,

因此需要选择X86的目标机器编译才不会有问题,具体设置如下图所示: using (SPSite site = new SPSite("http://www.test.com"))

System.IO.FileNotFoundException was unhandled

Message="找不到位于 http://www.test.com 的 Web 应用程序。请确认正确键入了此 URL。如果此 URL 需要提供现有内容,则系统管理员可能需要添加到指定应用程序的新请求 URL 映射。"

Source="Microsoft.SharePoint"

StackTrace:

在 Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)

在 Microsoft.SharePoint.SPSite..ctor(String requestUrl)

在 ConsoleApplication3.Program.Validate() 位置 e:\Visual Studio 2005\Projects\ConsoleApplication3\ConsoleApplication3\Program.cs:行号 79

在 ConsoleApplication3.Program.Main(String[] args) 位置 e:\Visual Studio 2005\Projects\ConsoleApplication3\ConsoleApplication3\Program.cs:行号 21

在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)

在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)

在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

在 System.Threading.ThreadHelper.ThreadStart()

莫名其妙,但是可以肯定地是由于编译平台X86的原因,于是此路不通,只得在SharPoint里面调用Web Service对列表字段进行操作,也深刻的体会到了Web Service的妙处,同时意识到平时自己做的Web Service是多么的不规范,调用,或者发布Web Service,都只能使用XML,这才是通用的,否则就失去意义,通过Web Service 对SharePoint 列表的操作代码如下,里面有详细的注释,应该没什么问题

com.test.www.Lists listService = new com.test.www.Lists();

listService.Credentials =

System.Net.CredentialCache.DefaultCredentials;

listService.Url =

"http://www.test.com/_vti_bin/Lists.asmx";

System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

System.Xml.XmlElement batchElement = doc.CreateElement("Batch");

batchElement.SetAttribute("OnError", "Continue");

batchElement.SetAttribute("ListVersion", "1");

batchElement.SetAttribute("所有项目",

batchElement.InnerXml = "<Method ID='1' Cmd='Update'>" +//此ID是Method的执行顺序

"<Field Name='ID'>6</Field>" + //此ID是SPListItem的ID,更新或者删除的时候才有用

"<Field Name='Title'>sixth</Field></Method>" + //需要更新的字段及其值

"<Method ID='2' Cmd='New'>" +//此ID是Method的执行顺序

"<Field Name='ID'>7</Field>" +//此ID是SPListItem的ID,新建的时候此值无效,可以不填

"<Field Name='Title'>seventh</Field></Method>";//新建时字段的值

//Update list items.

listService.UpdateListItems("Test", batchElement);
到此,问题基本上解决了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: