Calling a SOAP service with detergentex

Anyone have experience with accessing a SOAP service with the library detergentex?

My unsucessful attempt:

wsdl = Detergentex.Client.init_model(wsdl_url)
Detergentex.call(wsdl, "searchBasic", ["sequlla"])

Error:
(throw) {:error, 'Struct doesn\'t match model: recordtype not expected: p:searchBasic'}

I verified the wsdl url is correct and the operation ‘searchBasic’ exists.

What am I missing?

Thanks.

1 Like

Do you have the URL for WSDL? I took a quick look at the source, seems like second parameter for Detergentex.init_model/2 is a 'p' prefix. My guess, try: Detergentex.init_model(wsdl_url, '') to initialize model/client (mind the single quotes)

1 Like

Hello , I have been trying to write code for receiving data by Soap, but I have an error.

Please see following code :

wsdl_url = "https://sandbox.zarinpal.com/pg/services/WebGate/wsdl"
    action = "PaymentRequest"
    merchantid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
    description = "this is test"
    email = "m@m.com"
    mobile = "09361111111"
    callbackurl = "http://localhost/pay_back"
  price = 100
    parameters = [merchantid, price, description, email, mobile, callbackurl]
    wsdl = Detergentex.init_model(wsdl_url, '')

 Detergentex.call(wsdl, action, parameters)

and the error :

** (MatchError) no match of right hand side value: {:error, :enoent}
    src/detergent.erl:411: :detergent.get_url_file/1
    src/detergent.erl:337: :detergent.parseWsdls/5
    src/detergent.erl:320: :detergent.initModel2/5

I am using https://github.com/r-icarus/detergentex .

This is only a quickshot, but have you started detergentex properly?

1 Like

Taking a closer look at the code mentioned in your stacktrace, I see this function:

It tries to read from a file. and file:read_file/1 does return {error, enoent} when the file to read does not exist.

So, however you pass in that filename, it seems to not exist.

PS: I did a quick glance on the remainder of the get_url_file/1 function and it seems as if it were not supporting HTTPS Urls, That seems to be fixed in master of detergent, so you need to ask for a new release there, use HTTP instead or try to use a dep-override to a git-dep. But I am not sure what other problems you might pull in by the latter…

1 Like

i have same error
and I used
Detergentex.init_model(wsdl_url, '')

but not fix my problem

this is my test

url = Detergentex.init_model("http://localhost/php_test/server.php?wsdl", '')

output:

{:wsdl,
 [
   {:operation, 'Library', 'BookLibrary', 'bookYear', 'Library',
    'http://localhost/php_test/server.php',
    'http://localhost/php_test/server.php'}
 ],
 {:model,
  [
    {:type, :_document, :sequence,
     [
       {:el,
        [
          {:alt, :"soap:Header", :"soap:Header", [], 1, 1, true, :undefined},
          {:alt, :"soap:Fault", :"soap:Fault", [], 1, 1, true, :undefined},
          {:alt, :"soap:Envelope", :"soap:Envelope", [], 1, 1, true, :undefined},
          {:alt, :"soap:Body", :"soap:Body", [], 1, 1, true, :undefined}
        ], 1, 1, :undefined, 3}
     ], [], :undefined, :undefined, 1, 1, 1, false, :undefined},
    {:type, :"pp:book", :sequence,
     [
       {:el, [{:alt, :name, {:"#PCDATA", :char}, [], 1, 1, true, :undefined}],
        1, 1, :undefined, 3},
       {:el, [{:alt, :year, :"pp:integer", [], 1, 1, true, :undefined}], 1, 1,
        :undefined, 4}
     ], [], :undefined, :undefined, 3, 1, 1, :undefined, :undefined},
    {:type, :"soap:Body", :sequence,
     [
       {:el,
        [
          {:alt, :"#any", :any, [], 1, 1, true,
           {:anyInfo, 'lax', '##any',
            'http://schemas.xmlsoap.org/soap/envelope/'}}
        ], 0, :unbound, :undefined, 3}
     ], [],
     {:anyAttr, 'lax', '##any', 'http://schemas.xmlsoap.org/soap/envelope/'},
     :undefined, 2, 1, 1, :undefined, :undefined},
    {:type, :"soap:Envelope", :sequence,
     [
       {:el,
        [{:alt, :"soap:Header", :"soap:Header", [], 1, 1, true, :undefined}], 0,
        1, :undefined, 3},
       {:el, [{:alt, :"soap:Body", :"soap:Body", [], 1, 1, true, :undefined}],
        1, 1, :undefined, 4},
       {:el,
        [
          {:alt, :"#any", :any, [], 1, 1, true,
           {:anyInfo, 'lax', '##other',
            'http://schemas.xmlsoap.org/soap/envelope/'}}
        ], 0, :unbound, :undefined, 5}
     ], [],
     {:anyAttr, 'lax', '##other', 'http://schemas.xmlsoap.org/soap/envelope/'},
     :undefined, 4, 1, 1, :undefined, :undefined},
    {:type, :"soap:Fault", :sequence,
     [
       {:el,
        [{:alt, :faultcode, {:"#PCDATA", :qname}, [], 1, 1, true, :undefined}],
        1, 1, :undefined, 3},
       {:el,
        [{:alt, :faultstring, {:"#PCDATA", :char}, [], 1, 1, true, :undefined}],
        1, 1, :undefined, 4},
       {:el,
        [{:alt, :faultactor, {:"#PCDATA", :char}, [], 1, 1, true, :undefined}],
        0, 1, :undefined, 5},
       {:el, [{:alt, :detail, :"soap:detail", [], 1, 1, true, :undefined}], 0,
        1, :undefined, 6}
     ], [], :undefined, :undefined, 5, 1, 1, :undefined, :undefined},
    {:type, :"soap:Header", :sequence,
     [
       {:el,
        [
          {:alt, :"#any", :any, [], 1, 1, true,
           {:anyInfo, 'lax', '##other',
            'http://schemas.xmlsoap.org/soap/envelope/'}}
        ], 0, :unbound, :undefined, 3}
     ], [],
     {:anyAttr, 'lax', '##other', 'http://schemas.xmlsoap.org/soap/envelope/'},
     :undefined, 2, 1, 1, :undefined, :undefined},
    {:type, :"soap:detail", :sequence,
     [
       {:el,
        [
          {:alt, :"#any", :any, [], 1, 1, true,
           {:anyInfo, 'lax', '##any',
            'http://schemas.xmlsoap.org/soap/envelope/'}}
        ], 0, :unbound, :undefined, 3}
     ], [],
     {:anyAttr, 'lax', '##any', 'http://schemas.xmlsoap.org/soap/envelope/'},
     :undefined, 2, 1, 1, :undefined, :undefined}
  ],
  [
    {:ns, 'Library', 'pp', :unqualified},
    {:ns, 'http://schemas.xmlsoap.org/soap/envelope/', 'soap', :unqualified},
    {:ns, 'http://www.w3.org/2001/XMLSchema', 'xsd', :qualified}
  ], 'http://schemas.xmlsoap.org/soap/envelope/', [], true, :skip}, :undefined}

and next i call :
Detergentex.call(url, "bookYear", ["test"])

output:

** (throw) {:error, 'Struct doesn\'t match model: recordtype not expected: p:bookYear'}
    (erlsom) /home/mojtaba/Desktop/shahryar/elixir/zarinpal/deps/erlsom/src/erlsom_write.erl:381: :erlsom_write.findAlternative/4
    (erlsom) /home/mojtaba/Desktop/shahryar/elixir/zarinpal/deps/erlsom/src/erlsom_write.erl:269: :erlsom_write.processSubType/5
    (erlsom) /home/mojtaba/Desktop/shahryar/elixir/zarinpal/deps/erlsom/src/erlsom_write.erl:252: :erlsom_write.processElementValues/7
    (erlsom) /home/mojtaba/Desktop/shahryar/elixir/zarinpal/deps/erlsom/src/erlsom_write.erl:143: :erlsom_write.struct2xml/6
    (erlsom) /home/mojtaba/Desktop/shahryar/elixir/zarinpal/deps/erlsom/src/erlsom_write.erl:341: :erlsom_write.processAlternativeValue/8
    (erlsom) /home/mojtaba/Desktop/shahryar/elixir/zarinpal/deps/erlsom/src/erlsom_write.erl:252: :erlsom_write.processElementValues/7
    (erlsom) /home/mojtaba/Desktop/shahryar/elixir/zarinpal/deps/erlsom/src/erlsom_write.erl:127: :erlsom_write.struct2xml/6
    (erlsom) /home/mojtaba/Desktop/shahryar/elixir/zarinpal/deps/erlsom/src/erlsom_write.erl:341: :erlsom_write.processAlternativeValue/8
    (erlsom) /home/mojtaba/Desktop/shahryar/elixir/zarinpal/deps/erlsom/src/erlsom_write.erl:252: :erlsom_write.processElementValues/7
    (erlsom) /home/mojtaba/Desktop/shahryar/elixir/zarinpal/deps/erlsom/src/erlsom_write.erl:50: :erlsom_write.write/3
    src/detergent.erl:211: :detergent.call_attach/8

my wsdl api test by php soap and worked fine.

Well, detergentex is only available in version 0.0.7 and was released September 2015. Its only dependency detergent is of the same age.

If I were you, I’d search for alternatives.

1 Like

Hi, I think there’s a bug in: https://github.com/r-icarus/detergentex/blob/master/lib/detergentex/client.ex#L10, else clause is missing so wsdl will be nil if you passed a valid wsdl. It also means you can’t use a custom prefix for your calls. As @NobbZ suggested, I’d look for alternatives as detergentex doesn’t seem to be updated atm.

BTW, it’s handy if you supply the WSDL next time, so people can try it out for themselves :wink:

1 Like