Using Erlang for Comsuming Web Services using SOAP
Erik Reitsma EJ (RY/ETM)
erik.ej.reitsma@REDACTED
Thu Jan 13 08:52:06 CET 2005
Hi Neil,
I wrote that library for some SOAP stuff I had to do. No documentation exists (to my knowledge), because I used to be the only user. I am already proud that I put some comments in the source. :) Then I decided to give away the code, but without putting more effort in it. So, it is as it is.
I have used it mainly as a SOAP server, but there is a small client part too. I have not used that for a while, so it may be incompatible with recent inets changes. It is also written when xmerl-0.19 or even earlier was available, so it may be incompatible with the latest (official) xmerl. I have not tried that.
I am not sure when I am going to use this library again myself, so it is not actively maintained. It is "dormant", but I may wake it up when I need it.
I am sure that my SOAP implementation leaves a lot to be desired, but for my needs it was good enough.
About the client part. Before you can call soapclient:invoke/4 you have to define the operations, types and messages you want to use. (It would be nice if this could be generated from WSDL.)
Example:
-include("erlsoap.hrl").
-define(PARLAYX_SMS_XSD_URI,'http://www.csapi.org/schema/parlayx/common/v1_0').
add_messages() ->
%% sendSms operation
erlsoap:add_operation({'http://www.csapi.org/wsdl/parlayx/sms',
"sendSms"},
{'http://www.csapi.org/wsdl/parlayx/sms/v1_0/service',
"SendSMS_sendSmsRequest"},
{'http://www.csapi.org/wsdl/parlayx/sms/v1_0/service',
"SendSMS_sendSmsResponse"},
[]),
%% sendSms request message
erlsoap:add_message({'http://www.csapi.org/wsdl/parlayx/sms/v1_0/service',
"SendSMS_sendSmsRequest"},
[{"destinationAddressSet",{?PARLAYX_SMS_XSD_URI,"ArrayOfEndUserIdentifier"}},
{"senderName",{?XMLSchemaURI,"string"}},
{"charging",{?XMLSchemaURI,"string"}},
{"message",{?XMLSchemaURI,"string"}}]),
%% sendSms response message
erlsoap:add_message({'http://www.csapi.org/wsdl/parlayx/sms/v1_0/service',
"SendSMS_sendSmsResponse"},
[{{?PARLAYX_SMS_XSD_URI,"result"},
{?XMLSchemaURI,"string"}
}
]),
%% getSmsDeliveryStatus operation
erlsoap:add_operation({'http://www.csapi.org/wsdl/parlayx/sms',
"getSmsDeliveryStatus"},
{'http://www.csapi.org/wsdl/parlayx/sms/v1_0/service',
"SendSMS_getSmsDeliveryStatusRequest"},
{'http://www.csapi.org/wsdl/parlayx/sms/v1_0/service',
"SendSMS_getSmsDeliveryStatusResponse"},
[]),
%% getSmsDeliveryStatus request message
erlsoap:add_message({'http://www.csapi.org/wsdl/parlayx/sms/v1_0/service',
"SendSMS_getSmsDeliveryStatusRequest"},
[{"requestIdentifier",{?XMLSchemaURI,"string"}}]),
%% getSmsDeliveryStatus response message
erlsoap:add_message({'http://www.csapi.org/wsdl/parlayx/sms/v1_0/service',
"SendSMS_getSmsDeliveryStatusResponse"},
[{{?PARLAYX_SMS_XSD_URI,"result"},
{'http://www.csapi.org/schema/parlayx/sms/v1_0',"ArrayOfDeliveryStatusType"}
}
]),
%% EndUserIdentifier type
erlsoap:add_type({?PARLAYX_SMS_XSD_URI,"EndUserIdentifier"},
{complex_type,
{sequence,
[{"value",{?XMLSchemaURI,"string"},0,1}]
}
}),
erlsoap:add_type({'http://www.csapi.org/schema/parlayx/sms/v1_0',"ArrayOfDeliveryStatusType"},
{complex_type,
{sequence,
[{"ArrayOfDeliveryStatusType",
{'http://www.csapi.org/schema/parlayx/sms/v1_0',
"DeliveryStatusType"},0,unbounded}
]
}
}),
erlsoap:add_type({?PARLAYX_SMS_XSD_URI,"ArrayOfEndUserIdentifier"},
{complex_type,
{array,
{?PARLAYX_SMS_XSD_URI,"EndUserIdentifier"}
}
}),
erlsoap:add_type({'http://www.csapi.org/schema/parlayx/sms/v1_0',"ArrayOfSmsType"},
{complex_type,
{sequence,
[{"ArrayOfSmsType",
{'http://www.csapi.org/schema/parlayx/sms/v1_0',
"SmsType"},0,unbounded}
]
}
}),
erlsoap:add_type({'http://www.csapi.org/schema/parlayx/sms/v1_0',"DeliveryStatusType"},
{complex_type,
{sequence,
[{"destinationAddress",
{?PARLAYX_SMS_XSD_URI,
"EndUserIdentifier"},0,1},
{"deliveryStatus",
{'http://www.csapi.org/schema/parlayx/sms/v1_0',"DeliveryStatus"},0,1}
]
}
}
),
erlsoap:add_type({'http://www.csapi.org/schema/parlayx/sms/v1_0',"SmsType"},
{complex_type,
{sequence,
[{"message",{?XMLSchemaURI,"string"}},
{"senderAddress",
{?PARLAYX_SMS_XSD_URI,
"EndUserIdentifier"},0,1}
]
}
}
),
erlsoap:add_type({'http://www.csapi.org/schema/parlayx/sms/v1_0',"DeliveryStatus"},
{simple_type,{restriction,
[{?XMLSchemaURI,"string"}],
[{enumeration,'Delivered'},
{enumeration,'DeliveryUncertain'},
{enumeration,'DeliveryImpossible'},
{enumeration,'MessageWaiting'}]
}
}),
erlsoap:add_type({'http://www.csapi.org/schema/parlayx/sms/v1_0',"SmsFormat"},
{simple_type,{restriction,
[{?XMLSchemaURI,"string"}],
[{enumeration,'Ems'},
{enumeration,'SmartMessaging'}]
}
}).
Then you should be able to call the service:
send_sms_local(X,Message) ->
soapclient:invoke("http://some.host.com:8888/soap/rpcrouter",
"\"SendSMS#sendSms\"",
{'http://www.csapi.org/wsdl/parlayx/sms',
"sendSms"},
[[[X]],["tel:1234"],"no bill",Message]).
I hope this helps a little.
Kind regards,
*Erik.
More information about the erlang-questions
mailing list