Elixir call Axis2 Java SOAP Web Service with deter

2019-03-18 09:15发布

From Elixir, I am trying to call a SOAP Web Service with detergentex, which is a wrapper around the Erlang library detergent.

I can call the SOAP Web Service in the example on the detergent home page with no problems: http://www.webservicex.net/convertVolume.asmx?WSDL

Parameters:

wsdl_url = "http://www.webservicex.net/convertVolume.asmx?WSDL"
action = "ChangeVolumeUnit"
parameters = ["100","dry","centiliter"]

However when trying to call an Axis2 Java SOAP Web Service I am having some problems. Example: http://www.thomas-bayer.com/axis2/services/BLZService?wsdl

When calling "getBank" in the following way

wsdl_url = "http://www.thomas-bayer.com/axis2/services/BLZService?wsdl"
action = "getBank"
parameters = ["abc"]
wsdl = Detergentex.init_model(wsdl_url)
res = Detergentex.call(wsdl, action, parameters)

I get the following error message:

{:error, 'Struct doesn\'t match model: recordtype not expected: p:getBank'}

with the following stack trace

    src/erlsom_write.erl:357: :erlsom_write.findAlternative/4
    src/erlsom_write.erl:258: :erlsom_write.processSubType/5
    src/erlsom_write.erl:241: :erlsom_write.processElementValues/7
    src/erlsom_write.erl:132: :erlsom_write.struct2xml/6
    src/erlsom_write.erl:323: :erlsom_write.processAlternativeValue/8
    src/erlsom_write.erl:241: :erlsom_write.processElementValues/7
    src/erlsom_write.erl:116: :erlsom_write.struct2xml/6
    src/erlsom_write.erl:323: :erlsom_write.processAlternativeValue/8
    src/erlsom_write.erl:241: :erlsom_write.processElementValues/7
    src/erlsom_write.erl:45: :erlsom_write.write/2
    src/detergent.erl:211: :detergent.call_attach/8

Any suggestions as to what I'm doing wrong?

2条回答
姐就是有狂的资本
2楼-- · 2019-03-18 09:50

According to the implementation a prefix is added on the init_model.

def init_model(wsdl_url, prefix \\ 'p') do
   Detergentex.Client.init_model(wsdl_url, prefix)
end

I would suggest to add an empty prefix.

查看更多
不美不萌又怎样
3楼-- · 2019-03-18 09:54

This code

 def is_wsdl(wsdl), do: :detergent.is_wsdl(wsdl)

 def wsdl_operations(wsdl), do: :detergent.wsdl_operations(wsdl)

in detergentex/lib/detergentex/client.ex should be replaced with

 def is_wsdl(wsdl) do 
   :detergent.is_wsdl(wsdl)
 end

 def wsdl_operations(wsdl) do 
   :detergent.wsdl_operations(wsdl)
 end

so you will avoid a bug with incorrect prefix. I don't know what is wrong because both versions seem legit.

Your code will not work anyway - a new error appears :/

I have a different errors with my code for the url:

wsdl_url = 'http://webapi.allegro.pl/service.php?wsdl'

The first one:

** (throw) {:error, 'Struct doesn\'t match model: recordtype not expected: p:doQuerySysStatus'}
src/erlsom_write.erl:366: :erlsom_write.findAlternative/4
src/erlsom_write.erl:256: :erlsom_write.processSubType/5
src/erlsom_write.erl:239: :erlsom_write.processElementValues/7
src/erlsom_write.erl:130: :erlsom_write.struct2xml/6
src/erlsom_write.erl:326: :erlsom_write.processAlternativeValue/8
src/erlsom_write.erl:239: :erlsom_write.processElementValues/7
src/erlsom_write.erl:114: :erlsom_write.struct2xml/6
src/erlsom_write.erl:326: :erlsom_write.processAlternativeValue/8

and after correcting:

** (Protocol.UndefinedError) protocol String.Chars not implemented for {:ok, :undefined, :undefined}
(elixir) lib/string/chars.ex:3: String.Chars.impl_for!/1
(elixir) lib/string/chars.ex:17: String.Chars.to_string/1
(elixir) lib/io.ex:429: IO.puts/2

So this time it looks like it is something wrong with encoding I suppose.

查看更多
登录 后发表回答