【问题】
在折腾C#中实现metaWeblog的getPost方法,写了测试代码:
class openPost : XmlRpcClientProtocol
{
[XmlRpcMethod("metaWeblog.getPost")]
//http://xmlrpc.scripting.com/metaWeblogApi.html
//metaWeblog.getPost (postid, username, password) returns struct
//The blogid, username, password and publish params are as in the Blogger API. newPost returns a string representation of the post id, again as defined by the Blogger API. The struct is where the juice is.
public string getPost(string postid, string username, string password)
{
return (string)this.Invoke("getPost", new object[] { postid, username, password });
}
}运行出错:
An unhandled exception of type ‘CookComputing.XmlRpc.XmlRpcMissingUrl’ occurred in CookComputing.XmlRpcV2.dll
Additional information: Proxy XmlRpcUrl attribute or Url property not set.
【解决过程】
1.明显是缺少了XmlRpcUrl的设置。
所以就去添加了对应的设置:
| [XmlRpcUrl(https://www.crifan.com/xmlrpc.php)] |
但是编译的时候又出错:
| D:\xxx\OpenPostViaPermaLink\openPost.cs(73,10): error CS0592: Attribute ‘XmlRpcUrl’ is not valid on this declaration type. It is only valid on ‘class, interface’ declarations. |
2.网上找了半天,看到这里:
然后就修改了对应代码,经过一番折腾,用如下代码:
using System;
using System.Collections.Generic;
using System.Text;
using CookComputing.XmlRpc;
namespace OpenPostViaPermaLink
{
[XmlRpcUrl("https://www.crifan.com/xmlrpc.php")]
class CrifanMetaWeblog : XmlRpcClientProtocol
{
[XmlRpcMethod("metaWeblog.getPost")]
//http://xmlrpc.scripting.com/metaWeblogApi.html
//metaWeblog.newPost (blogid, username, password, struct, publish) returns string
//metaWeblog.editPost (postid, username, password, struct, publish) returns true
//metaWeblog.getPost (postid, username, password) returns struct
//The blogid, username, password and publish params are as in the Blogger API. newPost returns a string representation of the post id, again as defined by the Blogger API. The struct is where the juice is.
public Object getPost(string postid, string username, string password)
{
Object retInfo = null;
retInfo = this.Invoke("getPost", new object[] { postid, username, password });
return retInfo;
}
}
}
// calling function
void xmlRpcTest()
{
CrifanMetaWeblog crifanBlog = new CrifanMetaWeblog();
string postid = "7064";
string username = "yourname";
string password = "yourpassword";
Object retPostInfo = crifanBlog.getPost(postid, username, password);
}最后可以成功获得对应帖子的信息了
| retInfo Count = 22 object {CookComputing.XmlRpc.XmlRpcStruct} [“permaLink”] “https://www.crifan.com/tmp_test_open_post_via_permanent_link/” |
剩下的,就可以一点点实现其他所需要的功能了,包括editPost,newPost等。
转载请注明:在路上 » 【已解决】Additional information: Proxy XmlRpcUrl attribute or Url property not set和error CS0592: Attribute ‘XmlRpcUrl’ is not valid on this declaration type
