English 中文(简体)
利用c#在断层中创造节点
原标题:using c# to create node in drupal

i need to make a ("webservice") c# app that can create/update/delete nodes for/from drupal 7 using xmlrpc. everytime i run my app i get errors from the xmlrpc files(library). I tried to find code/documentation for C# using xmlrpc to connect to drupal, but in vain. I would be nice if you could point me in the right direction, or share some c# code with me.

{
[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] 服务器错误。 未具体说明的请购方法。 - 在XmlRpcSerializer.cs

Thank you, Florin

最佳回答

如果你重新使用第7博士的话,你必须使用第3号服务,该服务有<编码>node.get方法(或node.save 发生时)。 改为node.retrieve<>和node.create &node.update

您可在服务单元的夹中查阅<代码>资源/信息-资源.inc文档中的所有可用方法。

<>>>>>

在内部,请标书使用<代码>drupal_execute提交,后者是用来提交表格的功能。 由于该机构是Droupal的一个领域,因此它有望成为一种多维的阵列(PHP版本):

$data["body"][$language][0]["value"]

www.un.org/Depts/DGACM/index_spanish.htm ANOTHER UPDATE

Java XML-RPC的客户实例 缩略语 这样,我最好的猜测是,你可以使用<条码>。 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#中编造,从而消除了那里的任何错误。 同样,我确信,可以更有效地宣布它,但我已忘记,大多数语言是诚实的!

问题回答

Jan s answer is not quite right. If you are using the cook xmlrpc library all you would need to do is this:

        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);

Unfortunately, the body params need to be an array of struct under the "und" key with only one value. I blame this on the sloppiness of the drupal xmlrpc API.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签