我需要做一个("webservice") c#应用程序,它可以使用xmlrpc为Drupal7创建/更新/删除节点。每次我运行我的应用程序时,我都会收到来自xmlrpc文件(库)的错误。我尝试使用xmlrpc连接到C#来查找drupal的代码/文档,但是徒劳无功。如果你能给我指出正确的方向,或者与我分享一些c#代码,我会很高兴。
{
[XmlRpcUrl("http://testing/testserver")]
public interface IDrupalServices
{
[XmlRpcMethod("node.get")]
XmlRpcStruct NodeLoad(int nid, string[] field);
[XmlRpcMethod("node.save")]
void NodeSave(XmlRpcStruct node);
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
IDrupalServices drupal = XmlRpcProxyGen.Create<IDrupalServices>();
int nid = 227;
string[] fields = new string[] { };
XmlRpcStruct node = drupal.NodeLoad(nid, fields);
string teaser = node["teaser"].ToString();
welcomeTxt.Text = teaser;
}
private void button1_Click(object sender, EventArgs e)
{
string title = txtTitle.Text;
string body = txtBody.Text;
IDrupalServices drupal = XmlRpcProxyGen.Create<IDrupalServices>();
XmlRpcStruct node = new XmlRpcStruct();
node["id"] = 1001;
node["title"] = title;
node["body"] = body;
node["teaser"] = body;
node["format"] = 1;
node["type"] = "webservice";
node["promote"] = false;
drupal.NodeSave(node);
MessageBox.Show("The post was been created!");
}
}
}运行此命令后,我得到错误:服务器返回故障异常:-32601服务器错误。未指定请求的方法node.get。-在XmlRpcSerializer.cs中
谢谢你,弗洛林
发布于 2012-01-15 06:18:26
如果您使用的是Drupal7,那么您必须使用Services3,它没有node.get方法(或者碰巧没有node.save )。它们分别被node.retrieve和node.create & node.update所取代。
您可以查看“服务”模块文件夹中resources/node_resource.inc文件中的所有可用方法。
更新
在内部,节点使用drupal_execute提交,这是用于提交表单的函数。因为body在Drupal中是一个字段,所以它应该是这种格式(PHP版本)的多维数组:
$data["body"][$language][0]["value"]$language要么是节点的特定语言,要么是未定义语言的und (除非您处理的是多语言站点,通常使用und )。您需要构建一个类似于C#代码中的数组,并且Drupal应该保存它。
另一个更新
Java XML-RPC client example for Services使用HashMap类型来完成此任务,所以我最好的猜测是您可以使用Dictionary (尽管它看起来不必要地复杂):
var innerValue = new Dictionary<string, string>();
innerValue.Add("value", txtBody.Text);
var language = new Dictionary<int, Dictionary<string, string>>();
language.Add(0, innerValue);
var body = new Dictionary<string, Dictionary<int, Dictionary<string, string>>>();
body.Add("und", language);
node["body"] = body;我已经有几年没有用C#编写代码了,所以请原谅其中的任何错误。此外,我很确定它可以更有效地声明,但老实说,我已经忘记了大部分语言!
发布于 2015-08-17 06:55:20
简的答案不完全正确。如果您使用的是cook库,那么您需要做的就是:
XmlRpcStruct postStruct = new XmlRpcStruct();
postStruct.Add("type", "article");
postStruct.Add("title", "wohoo another test");
XmlRpcStruct postBodyStructParams = new XmlRpcStruct();
postBodyStructParams.Add("value", "My body yaaay");
postBodyStructParams.Add("format", "filtered_html");
XmlRpcStruct[] postBodyStructParamsArr = new XmlRpcStruct[1];
postBodyStructParamsArr[0] = postBodyStructParams;
XmlRpcStruct postBodyStruct = new XmlRpcStruct();
postBodyStruct.Add("und", postBodyStructParamsArr);
postStruct.Add("body", postBodyStruct);不幸的是,主体参数需要是"und"键下只有一个值的结构数组。我将其归咎于drupal xmlrpc API的草率。
https://stackoverflow.com/questions/8865508
复制相似问题