Mozilla SOAP API

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Mozilla SOAP API

Damiano Albani
Hello,

I'd like to use the Mozilla SOAP API in an extension of my own inside
Sunbird. At first, I wanted to use the "shortcuts" API through the
JavaScript object types SOAP{Call,Parameter,...} [1]. Unfortunately,
I've been told that they are NOT available in an XPCOM component. Why is
it so ? Would it be difficult to change this situation ?
So, I turned to using the 'official' low-level XPCOM API [2]. I managed
to get Sunbird send basic SOAP messages -- except when encoding SOAP
parameters, which produces an 'SOAP_PROPERTYBAG_REQUIRED' error :

  When encoding as a struct, an object with properties is required.

This exception is raised in the function nsStructEncoder::Encode() [3],
for a reason I don't understand.

Here is the functions I wrote to 'mimic' the scriptable SOAP* object
types, and how I use them in an example :


function SOAPCall() {
        return Components.classes["@mozilla.org/xmlextras/soap/call;1"]
                         .createInstance(Components.interfaces.nsISOAPCall);
}

function SOAPMessage() {
        return Components.classes["@mozilla.org/xmlextras/soap/call;1"]
                         
.createInstance(Components.interfaces.nsISOAPMessage);
}

function SOAPParameter(aValue, aName, aNamespaceURI, aType) {
    var parameter =
Components.classes["@mozilla.org/xmlextras/soap/parameter;1"]
                                 
.createInstance(Components.interfaces.nsISOAPParameter);

    var variant = Components.classes["@mozilla.org/variant;1"]
                               
.createInstance(Components.interfaces.nsIWritableVariant);

    variant.setAsString(aValue);
    parameter.namespaceURI = aNamespaceURI;
    parameter.value = variant;
    parameter.name = aName;
    return parameter;
}

var parameters = new Array(new SOAPParameter("login_value", "login"),
new SOAPParameter("password_value", "password"));

var soapCall = new SOAPCall();
soapCall.transportURI = aTransportURI;
soapCall.encode(Components.interfaces.nsISOAPMessage.VERSION_1_1, "aMethod",
                "urn:aURI", 0, null, parameters.length, parameters);

This final encode() function call produces the
'SOAP_PROPERTYBAG_REQUIRED' error.

What did I do wrong ? Any help is welcome :-)

[1] http://www.xulplanet.com/references/objref/#webservice
[2] http://www.xulplanet.com/references/xpcomref/group_WebServices.html
[3]
http://lxr.mozilla.org/mozilla/source/extensions/webservices/soap/src/nsDefaultSOAPEncoder.cpp#943

Cheers,

--
Damiano ALBANI
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: Mozilla SOAP API

Doron Rosenberg-2
The "shortcuts" are only available on an DOM Document, which a xpcom
component doesn't have.

Why are you using a nsIVariant?  You should probably be using a js
object or a js array ([value] for example).

Damiano Albani wrote:

> Hello,
>
> I'd like to use the Mozilla SOAP API in an extension of my own inside
> Sunbird. At first, I wanted to use the "shortcuts" API through the
> JavaScript object types SOAP{Call,Parameter,...} [1]. Unfortunately,
> I've been told that they are NOT available in an XPCOM component. Why is
> it so ? Would it be difficult to change this situation ?
> So, I turned to using the 'official' low-level XPCOM API [2]. I managed
> to get Sunbird send basic SOAP messages -- except when encoding SOAP
> parameters, which produces an 'SOAP_PROPERTYBAG_REQUIRED' error :
>
>  When encoding as a struct, an object with properties is required.
>
> This exception is raised in the function nsStructEncoder::Encode() [3],
> for a reason I don't understand.
>
> Here is the functions I wrote to 'mimic' the scriptable SOAP* object
> types, and how I use them in an example :
>
>
> function SOAPCall() {
>        return Components.classes["@mozilla.org/xmlextras/soap/call;1"]
>                         .createInstance(Components.interfaces.nsISOAPCall);
> }
>
> function SOAPMessage() {
>        return Components.classes["@mozilla.org/xmlextras/soap/call;1"]
>                        
> .createInstance(Components.interfaces.nsISOAPMessage);
> }
>
> function SOAPParameter(aValue, aName, aNamespaceURI, aType) {
>    var parameter =
> Components.classes["@mozilla.org/xmlextras/soap/parameter;1"]
>                                  
> .createInstance(Components.interfaces.nsISOAPParameter);
>
>    var variant = Components.classes["@mozilla.org/variant;1"]
>                                
> .createInstance(Components.interfaces.nsIWritableVariant);
>
>    variant.setAsString(aValue);
>    parameter.namespaceURI = aNamespaceURI;
>    parameter.value = variant;
>    parameter.name = aName;
>    return parameter;
> }
>
> var parameters = new Array(new SOAPParameter("login_value", "login"),
> new SOAPParameter("password_value", "password"));
>
> var soapCall = new SOAPCall();
> soapCall.transportURI = aTransportURI;
> soapCall.encode(Components.interfaces.nsISOAPMessage.VERSION_1_1,
> "aMethod",
>                "urn:aURI", 0, null, parameters.length, parameters);
>
> This final encode() function call produces the
> 'SOAP_PROPERTYBAG_REQUIRED' error.
>
> What did I do wrong ? Any help is welcome :-)
>
> [1] http://www.xulplanet.com/references/objref/#webservice
> [2] http://www.xulplanet.com/references/xpcomref/group_WebServices.html
> [3]
> http://lxr.mozilla.org/mozilla/source/extensions/webservices/soap/src/nsDefaultSOAPEncoder.cpp#943 
>
>
> Cheers,
>
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: Mozilla SOAP API

Damiano Albani
Doron Rosenberg wrote:
> The "shortcuts" are only available on an DOM Document, which a xpcom
> component doesn't have.
>
> Why are you using a nsIVariant?  You should probably be using a js
> object or a js array ([value] for example).

You're right -- it has no sense using nsIVariant here.
However, now I'm trying to use the WSDL proxy with document/literal
SOAP, instead of the "usual" rpc/encoded.
I took one of the WSDL files of the Google's AdWords SOAP API [1] and
made some tests. The proxy correctly exposes the SOAP operations as JS
functions, but I don't know what parameters to pass. All I managed to
get is NS_ERROR_NOT_AVAILABLE errors :/
How can I make this work ?

Cheers,

[1] https://adwords.google.com/api/adwords/v2/InfoService?wsdl

--
Damiano ALBANI
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: Mozilla SOAP API

Damiano Albani
Damiano Albani wrote:

> All I managed to
> get is NS_ERROR_NOT_AVAILABLE errors :/

This error is generated in the function EncodeStructParticle() [1],
caused by a the presence of a non-null namespace :

832       if (!name.IsEmpty()) {
833         rc = NS_ERROR_NOT_AVAILABLE; //  No known way to use
namespace qualification in struct
834       }

What does that mean ? How can I solve this issue (WSDL rewrite, etc) ?

[1]
http://lxr.mozilla.org/mozilla1.8/source/extensions/webservices/soap/src/nsDefaultSOAPEncoder.cpp#832

Cheers,

--
Damiano ALBANI
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: Mozilla SOAP API

Doron Rosenberg-2
In reply to this post by Damiano Albani
Damiano Albani wrote:

> Damiano Albani wrote:
>
>> All I managed to get is NS_ERROR_NOT_AVAILABLE errors :/
>
> This error is generated in the function EncodeStructParticle() [1],
> caused by a the presence of a non-null namespace :
>
> 832       if (!name.IsEmpty()) {
> 833         rc = NS_ERROR_NOT_AVAILABLE; //  No known way to use
> namespace qualification in struct
> 834       }
>
> What does that mean ? How can I solve this issue (WSDL rewrite, etc) ?
>
> [1]
> http://lxr.mozilla.org/mozilla1.8/source/extensions/webservices/soap/src/nsDefaultSOAPEncoder.cpp#832 
>
>
> Cheers,
>
You'll need to post your code somewhere (perhaps pastebin.com).
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: Mozilla SOAP API

Damiano Albani
Doron Rosenberg wrote:
> You'll need to post your code somewhere (perhaps pastebin.com).

The JavaScript is available at : <http://pastebin.com/552839>.
And the WSDL is at : <http://pastebin.com/552844>.

Cheers,

--
Damiano ALBANI

_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml