XmlRpcService
; abstract and implementing the widely known System.Web.IHttpHandler
. To create your own XML-RPC service, it is enough to inherit from this class and mark the methods XmlRpcServiceMethodAttribute
attribute:public class MathXmlRpcService : octalforty.Brushie.Web.XmlRpc.XmlRpcService
{
[XmlRpcServiceMethod("add")]
public int Add(int x, int y)
{
return x + y;
}
}
int
is) this is enough. If you need to transfer structures (the word “structure” I use in relation to XML-RPC, and not to .NET), then the class (here we are already talking about .NET) must be further marked:[XmlRpcStructure()]
public class BlogPostCategory
{
private string title = String.Empty;
[XmlRpcMember("title")]
public string Title
{
get { return title; }
set { title = value; }
}
}
octalforty.Brushie.Web.XmlRpc.XmlRpcService
and all the related infrastructure, it is up to you to understand the rather vague specification and write the appropriate code. Taking Fiddler in one hand and Windows Live Writer in the other, I began research. As a result, came out such a stone flower .XmlRpcService
and implement IMetaWeblogService
.NewMediaObject
implementation looks like.namespace octalforty.Kudos.Web.Api.Wiki
{
/// /// A MetaWeblog XML-RPC service for editing wiki pages.
///
public class MetaWeblogService : XmlRpcService, IMetaWeblogService, IPageManagerServiceDependency,
ISpaceManagerServiceDependency, INavigationServiceDependency,
IGlobalTagManagerServiceDependency, ISecurityServiceDependency,
IUserManagerServiceDependency, IPageAttachmentManagerServiceDependency
{
public MediaObjectInfo NewMediaObject(string blogID, string login, string password, MediaObject mediaObject)
{
if(!SecurityService.IsValid(login, password))
throw new SecurityException();
//
// Parsing media object name.
if(mediaObject.Name.IndexOf("^") < 0)
throw new ArgumentException();
string pageName = mediaObject.Name.Substring(0, mediaObject.Name.IndexOf("^"));
string attachmentName = mediaObject.Name.Substring(mediaObject.Name.IndexOf("^") + 1);
Space space = SpaceManagerService.GetSpaceByID(Convert.ToInt64(blogID));
Page page = PageManagerService.GetPageBySpaceKeyAndPageName(space.Key, pageName);
PageAttachment pageAttachment = PageAttachmentManagerService.GetPageAttachmentByName(page, attachmentName);
if(pageAttachment == null)
{
pageAttachment = new PageAttachment(attachmentName, mediaObject.MimeType);
page.AddAttachment(pageAttachment);
} // if
pageAttachment.AddRevision(new PageAttachmentRevision(UserManagerService.GetUserByLogin(login), mediaObject.Content));
PageManagerService.SavePage(page);
return new MediaObjectInfo(NavigationService.ResolveVirtualUrl(NavigationService.GetPageAttachmentUrl(pageAttachment)));
}
}
}
Source: https://habr.com/ru/post/24792/
All Articles