elixir-soap/soap

expected a map, got: nil with Soap.call

juanpabloaj opened this issue Β· 21 comments

Hi, thanks for this module

When I tried to use call I got this message

{:ok, response} = Soap.call(wsdl, "myOperation", params)           
** (BadMapError) expected a map, got: nil
    (elixir) lib/map.ex:437: Map.get(nil, :type, nil)
    (soap) lib/soap/request/params.ex:193: Soap.Request.Params.add_action_tag_wrapper/3
    (soap) lib/soap/request/params.ex:118: Soap.Request.Params.build_soap_body/3
    (soap) lib/soap/request/params.ex:25: Soap.Request.Params.build_body/4
    (soap) lib/soap/request.ex:17: Soap.Request.call/5
    (soap) lib/soap.ex:91: Soap.call/5

what could be the problem?

Regards

Hi @juanpabloaj.
Which version of the library are you using?
Can you attach your WSDL file and full code to reproduce this error?

Hi @Nitrino,
reason for this error (at least in my case) is that WSDL section where types are defined is defined via link (<xs:schema xmlns:ns="http://foo.bar/" ... />) to other xml file, instead of direct types definitions.
This causes wsdl[:complex_types] to be empty list and Enum.find/2 on this list returns nil --> error described by @juanpabloaj is raised.
Tested on 1.0.1.

Hello I am having the same issue. The WSDL file can be found here: https://ics2wsa.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.147.wsdl
I am using 1.1

From what I have been playing with is:

  defp get_action_with_namespace(wsdl, operation) do
    wsdl[:complex_types]
    |> Enum.find(fn x -> x[:name] == operation end) . ###-> nil causing error from below
    |> handle_action_extractor_result(wsdl, operation)

In my case the operation is runTransaction which is not a complex type thus will aways be nil.

Hi guys.
I tried to fix this bug in fix-empty-complex-types brunch, but I do not have access to your server and I can not test.
@SullysMustyRuby Please set in your mix.exs:

{:soap, git: "https://github.com/elixir-soap/soap.git", branch: "fix-empty-complex-types"}

and try to call request

thanks @Nitrino, I changed the mix file to use the branch fix-empty-complex-types.

and to try it, I used this public wsdl/xsd files

https://gist.github.com/juanpabloaj/54668d78ee90a9932801ced17c4c72e9

source: https://www.w3.org/TR/2001/NOTE-wsdl-20010315

But I get this error message

Soap.init_model("stockquoteservice.wsdl")
** (MatchError) no match of right hand side value: nil
    (soap) lib/soap/wsdl.ex:48: Soap.Wsdl.get_schema_namespace/1
    (soap) lib/soap/wsdl.ex:30: Soap.Wsdl.parse/3

BTW, I tried the files with SoapUI and the files work.

Thanks a lot for your time.

Does anyone have an update on this error?
I tried the branch listed above but I still get the same error.

     ** (BadMapError) expected a map, got: nil
     code: {:ok, response} = Soap.call(wsdl, action, {headers, params})
     stacktrace:
       (elixir) lib/map.ex:451: Map.get(nil, :type, nil)
       (soap) lib/soap/request/params.ex:193: Soap.Request.Params.add_action_tag_wrapper/3
       (soap) lib/soap/request/params.ex:118: Soap.Request.Params.build_soap_body/3
       (soap) lib/soap/request/params.ex:25: Soap.Request.Params.build_body/4
       (soap) lib/soap/request.ex:17: Soap.Request.call/5
       (soap) lib/soap.ex:91: Soap.call/5
       test/soap_test.exs:206: (test)

wsdl file: http://connectivity.dingus-services.com/services/Tazzy/CustomServices/dingus/service.asmx?wsdl

test file

    {:ok, wsdl} = Soap.init_model(wsdl_path, :url)
    action = "Book"
    headers = Soap.Request.Headers.build(wsdl, "Book", [])
    params = %{something: "test1234"}

    {:ok, response} = Soap.call(wsdl, action, {headers, params})
    ... 

Hi @mthomps4 , thanks for the feedback.
I will try to investigate this problem in the coming days.

any news about this issue, @Nitrino? I got the branch version and its works :)

I just tried the fix-empty-complex-types branch and it seems to fix the issue for me.

Hi guys.
I'm sorry for the delay.
I added tests and merge in fix-empty-complex-types branch

@Nitrino I am still getting this error. Any ideas on why this might be happening to me? I am on version 1.0.1

@JackSoby a new tag has not been cut.
You can try it out by using the latest commit on master.

{:soap, git: "https://github.com/elixir-soap/soap.git", ref: "587f8a538084345fad01cb92e7c1ee9e51ca509d"},

@Ebtoulson Thank you but that still throws the error

@JackSoby try to remove deps and _build folders, after that use ref version as @Ebtoulson described.
This should help. Otherwise, upload your WSDL file for research.
After the tests, I will release a new version

@Nitrino thanks for all the help, I am new to SOAP but ive been writing elixir for awhile so any help would be appreciated.

Git wont allow me to upload my WSDL file, is there anything you could point out that i could look for?

@JackSoby Can you show the error stack trace?
You can also upload WSDL file in a zip archive

Awesome Thank you for the guidance.

Here is the stack trace.

** (BadMapError) expected a map, got: nil
    (elixir) lib/map.ex:423: Map.get(nil, :type, nil)
    (soap) lib/soap/request/params.ex:193: Soap.Request.Params.add_action_tag_wrapper/3
    (soap) lib/soap/request/params.ex:118: Soap.Request.Params.build_soap_body/3
    (soap) lib/soap/request/params.ex:25: Soap.Request.Params.build_body/4
    (soap) lib/soap/request.ex:17: Soap.Request.call/5
    (soap) lib/soap.ex:92: Soap.call/5
    (order_management_portal) lib/mix/tasks/soap_integration.ex:104: Mix.Tasks.OrderManagementPortal.SoapIntegration.run/1
    (mix) lib/mix/task.ex:314: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:80: Mix.CLI.run_task/2
    (elixir) lib/code.ex:677: Code.require_file/2

and here is the WSLD

RateService_v26 copy.wsdl.zip

@JackSoby
Indeed, an error occurs with your WSDL file.
I know the global cause of this and many more bugs, for the fix of which it is necessary to fully rewrite the parsing of data types.
Sorry, this is a lot of work and I can’t give an estimate.

Let's try to solve your problem together.
Try to add an additional type to your WSDL file that will help the library with parsing.

      <xs:element name="getRates" type="ns:RateRequest"/>

image

@Nitrino It looks like adding that lined fixed it. The call went through I just got an authentication error which is separate from your library.

Thanks so much for the help it is greatly appreciated!

alkx commented

@Nitrino I'm having the same error as above on version 1.0.1.

** (BadMapError) expected a map, got: nil
    (elixir 1.10.3) lib/map.ex:450: Map.get(nil, :type, nil)
    (soap 1.0.1) lib/soap/request/params.ex:193: Soap.Request.Params.add_action_tag_wrapper/3
    (soap 1.0.1) lib/soap/request/params.ex:118: Soap.Request.Params.build_soap_body/3
    (soap 1.0.1) lib/soap/request/params.ex:25: Soap.Request.Params.build_body/4
    (soap 1.0.1) lib/soap/request.ex:17: Soap.Request.call/5
    (soap 1.0.1) lib/soap.ex:91: Soap.call/5

I am using these steps:

{:ok, wsdl} = Soap.init_model("https://ppds.hitpromo.net/productDataV2RC1", :url)
headers = Soap.Request.Headers.build(wsdl, "getProduct", [])
params = %{wsVersion: "1.0.0", ...}
Soap.call(wsdl, "getProduct", {headers, params})
...

Any ideas on what may be happening?