开发者

Custom webservice in Umbraco 4.5 giving odd error

We've created a custom webservice in Umbraco to add (async) files and upload them. After upload the service is called with node and file-information to add a new node to the content tree.

At first our main problem was that the service was running outside of the Umbraco context, giving strange errors with get_currentuser.

Now, we inherit the umbraco BaseWebService from the umbraco.webservices dll and we've set all acces information in the settings file; we authenticatie before doing anything else using (correct and ugly-hardcoded) administrator.

When we now execute the webservice (from the browser or anything else) we get:

at umbraco.DataLayer.SqlHelper`1.ExecuteReader(String commandText, IParameter[] parameters)
   at umbraco.cms.businesslogic.CMSNode.setupNode()
   at umbraco.cms.businesslogic.web.Document.setupNode()
   at umbraco.cms.businesslogic.CMSNode..ctor(Int32 Id)
   at umbraco.cms开发者_开发问答.businesslogic.Content..ctor(Int32 id)
   at umbraco.cms.businesslogic.web.Document..ctor(Int32 id)
   at FileUpload.AddDocument(String ProjectID, String NodeID, String FileName)*

Where AddDocument is our method. The node (filename w/o extension) does not exist in the tree (not anywhere, it's a new filename/node). We've cleared the recycle bin, so it's not in there either.

Are we missing something vital, does anyone has a solution?

Below is the source for the webservice;

using umbraco.cms.businesslogic.web;
using umbraco.BusinessLogic;
using umbraco.presentation.nodeFactory;
using umbraco.cms.businesslogic.member;
using umbraco.cms;

/// <summary>
/// Summary description for FileUpload
/// </summary>
[WebService(Namespace = "http://umbraco.org/webservices/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class FileUpload : umbraco.webservices.BaseWebService //System.Web.Services.WebService
{

    private string GetMimeType(string fileName)
    {
        string mimeType = "application/unknown";
        string ext = System.IO.Path.GetExtension(fileName).ToLower();
        Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
        if (regKey != null && regKey.GetValue("Content Type") != null)
            mimeType = regKey.GetValue("Content Type").ToString();
        return mimeType;
    }

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }


    [WebMethod]
    public void AddDocument(string ProjectID, string NodeID, string FileName)
    {
        Authenticate("***", "***");
        string MimeType = GetMimeType(FileName); //"application/unknown";

        // Create node
        int nodeId = 1197; 
        string fileName = System.IO.Path.GetFileNameWithoutExtension(@"*****\Upload\" + FileName);

        string secGroups = "";

//EDIT DUE TO COMMENT: Behavior remains the same though
        Document node = umbraco.cms.businesslogic.web.Document.MakeNew(fileName.Replace(".", ""), new DocumentType(1049), umbraco.BusinessLogic.User.GetUser(0), nodeId);


        secGroups = "Intern";

        StreamWriter sw = null;
        try
        {
//EXCEPTION IS THROWN SOMEWHERE HERE
            Document doc = NodeLevel.CreateNode(fileName, "Bestand", nodeId);
            doc.getProperty("bestandsNaam").Value = fileName;
            byte[] buffer = System.IO.File.ReadAllBytes(@"****\Upload\" + FileName);

            int projectId = 0;
            int tempid = nodeId;
//EXCEPTION IS THROWN TO THIS POINT (SEE BELOW)


            try
            {
                Access.ProtectPage(false, doc.Id, 1103, 1103);
                Access.AddMembershipRoleToDocument(doc.Id, secGroups);
            }
            catch (Exception ex)
            {
        // write to file
            }

            try
            {
                doc.Publish(umbraco.BusinessLogic.User.GetUser(0));
                umbraco.library.UpdateDocumentCache(doc.Id);

                umbraco.content.Instance.RefreshContentFromDatabaseAsync();
            }
            catch (Exception ex)
            {
        // write to file
            }
            System.IO.File.Delete(FileName);

        }
        catch (Exception ex)
        {
            // THIS EXCEPTION IS CAUGHT!!
        }
    }
    public override umbraco.webservices.BaseWebService.Services Service
    {
        get { return umbraco.webservices.BaseWebService.Services.DocumentService; }
    }
}

If anyone has a solution, pointer, hint or whatever; help is appreciated!!

TIA, riffnl


We've rewritten the whole procedure (dumped all code and restart) and we've got it working now.

I think we've been messing around with the old code so much in trying to get it to work we were missing some key issues, because it functions.

Thanks for thinking along anyway!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜