locked
How to consume System Center Orchestrator services from Windows 8.1 app with HTML5/Javascript ?

    Question

  • Hi,

    I'm currently developping a Windows 8.1 app using HTML/Javascript but i don't know how to consume Orcehstrator web services using Javascript (or jQuery).

    I've found the C# sample but there is no indication about consuming theses REST based XML services with authentication and GET/PUT methods.

    Does anyone have an idea about that ?

    I'm pretty new to Windows Store apps developpment, Javascript and it will help me a lot if i could get a sample code or some explanations.

    Regards,

    Wednesday, March 19, 2014 4:37 PM

Answers

  • Here is what i did :

    var orchURL = 'http://myserver:81/Orchestrator2012/Orchestrator.svc/Jobs';
        var restPostMessage = '<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" \
            xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" \
            xmlns="http://www.w3.org/2005/Atom"> \
            <content type="application/xml"> \
            <m:properties> \
            <d:RunbookId m:type="Edm.Guid">' + runbookId + '</d:RunbookId> \
            <d:Parameters>&lt;Data&gt;&lt;Parameter&gt;&lt;ID&gt;{' + idParameter1 + '}&lt;/ID&gt;&lt;Value&gt;' + valueParameter1 + '&lt;/Value&gt;&lt;/Parameter&gt;&lt;Parameter&gt;&lt;ID&gt;{' + idParameter2 + '}&lt;/ID&gt;&lt;Value&gt;' + valueParameter2 + '&lt;/Value&gt;&lt;/Parameter&gt;&lt;/Data&gt;</d:Parameters> \
            </m:properties> \
            </content> \
            </entry>';
    
            $.ajax({
                type: "POST",
                url: orchURL,
                data: restPostMessage,
                contentType: "application/atom+xml; charset=\"utf-8\"",
                dataType: "xml",
                success: function (xml) {
                    myfunction("success");
                },
                error: function (xml) {
                    myfunction("error");
                }
            });
    

    It works fine.

    • Marked as answer by Shnabr Tuesday, March 25, 2014 5:37 PM
    Tuesday, March 25, 2014 5:37 PM

All replies

  • It's JavaScript, so the calls are the same whether it's in Windows Store or IE. Knowing that, I found this link for general knowledge of consuming RESTful webservices with JavaScript:

    http://blogs.msdn.com/b/brunoterkaly/archive/2011/11/17/how-to-consume-restful-services-using-jquery-and-or-javascript.aspx

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, March 19, 2014 7:27 PM
    Moderator
  • Thank you Matt, here is what i did :

    $.ajax({ type: "POST",
                url: http://myserver:81/Orchestrator2012/Orchestrator.svc/Jobs,
                data: '<?xml version="1.0" encoding="utf-8" standalone="yes"?><entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom"><content type="application/xml"><m:properties><d:RunbookId m:type="Edm.Guid">myRunbookID</d:RunbookId><d:Parameters>&lt;Data&gt;&lt;Parameter&gt;&lt;ID&gt;{myParam1ID}&lt;/ID&gt;&lt;Value&gt;myParam1Value&lt;/Value&gt;&lt;/Parameter&gt;&lt;Parameter&gt;&lt;ID&gt;{myParam2ID}&lt;/ID&gt;&lt;Value&gt;myParam2Value&lt;/Value&gt;&lt;/Parameter&gt;&lt;/Data&gt;</d:Parameters></m:properties></content></entry>',
                contentType: "text/xml",
                dataType: "xml",
                cache: false,
                success: function (xml) {
    
                    // Displaying toast notification
                    sendSuccessToast();
                },
                error: function (xml) {
                    
    // Displaying toast notification
                    sendErrorToast();
    
                        }});

    With this code i am able to contact my server myServer because it's asking to provide credentials. But when providing theses credentials, i get the sendErrorToast notification. I think that the communication process is not complete and not correct.

    How can i resolve this problem ? Does anyone have an idea of what i'm doing wrong ?


    • Edited by Shnabr Friday, March 21, 2014 2:21 PM
    Friday, March 21, 2014 2:20 PM
  • Here is what i did :

    var orchURL = 'http://myserver:81/Orchestrator2012/Orchestrator.svc/Jobs';
        var restPostMessage = '<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" \
            xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" \
            xmlns="http://www.w3.org/2005/Atom"> \
            <content type="application/xml"> \
            <m:properties> \
            <d:RunbookId m:type="Edm.Guid">' + runbookId + '</d:RunbookId> \
            <d:Parameters>&lt;Data&gt;&lt;Parameter&gt;&lt;ID&gt;{' + idParameter1 + '}&lt;/ID&gt;&lt;Value&gt;' + valueParameter1 + '&lt;/Value&gt;&lt;/Parameter&gt;&lt;Parameter&gt;&lt;ID&gt;{' + idParameter2 + '}&lt;/ID&gt;&lt;Value&gt;' + valueParameter2 + '&lt;/Value&gt;&lt;/Parameter&gt;&lt;/Data&gt;</d:Parameters> \
            </m:properties> \
            </content> \
            </entry>';
    
            $.ajax({
                type: "POST",
                url: orchURL,
                data: restPostMessage,
                contentType: "application/atom+xml; charset=\"utf-8\"",
                dataType: "xml",
                success: function (xml) {
                    myfunction("success");
                },
                error: function (xml) {
                    myfunction("error");
                }
            });
    

    It works fine.

    • Marked as answer by Shnabr Tuesday, March 25, 2014 5:37 PM
    Tuesday, March 25, 2014 5:37 PM