Technically,to create soap message, WSDL file is a must? - web-services

I'm using the SoapUI to generate the soap request. It hints me to input the wsdl file. I do it, and it create the soap-style message. Everything is OK.
But I have a doubt. If I have webservice without any WSDL file, can I still generate the soap-style message by hand? If it can, how to?
Or if I know the webservice need to input two int paramaters and return one string value, can I speculate the soap message only by these limited information?

If you are just doing -requests- then you don't need to have the WSDL file if you know the specific service you're asking and the parameters as you say. You can even do it by hand by creating the request and then sending it over HTTP (for example you could create it with your editor in a file and then send it via wget or curl).
As for an example I'll cite wikipedia:
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
</soap:Header>
<soap:Body>
<m:GetStockPrice xmlns:m="http://www.example.org/stock">
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
What you need to change is the parts in the soap:Body: of course the GetStockPrice (which is the service you're accessing) and StockName which is the parameter (in your case you may have more than one).
If in doubt you can put something to listen on a socket (for example netcat) and make your application with WSDL do a query to it and see the exact informations, then remove WSDL and work "by hand".

In Java: If you have webservice (annotated class etc.), the your server create one WSDL file when you deployed it. This WSDL you can use for soapUi.
If you have any structure (endpoint, class, XSD etc.), you can create soap message by hand.
If you weren't use WSDL for soap message, it wouldn't call/send this message. So the wsdl document is a required element according to the protocol. WSDL describes of how the service can be called, what parameters it expects, and what data structures it returns.
From Wikipedia:
WSDL is often used in combination with SOAP and an XML Schema to
provide Web services over the Internet. A client program connecting to
a Web service can read the WSDL file to determine what operations are
available on the server. Any special datatypes used are embedded in
the WSDL file in the form of XML Schema. The client can then use SOAP
to actually call one of the operations listed in the WSDL file using
for example XML over HTTP.
Here is in example for invoking web service dynamically. In this case the author doesn't know the description of the WSDL.

The purpose of the WSDL is to describe the service.
This machine-readable description allows computer programs to create clients that know how to call the service and process the responses.

Related

How can I call a ASP.Net made web service without using MSXML?

I am using a very particular language named “Magik”, I used to use MSXML2 to run web services but in one of my projects I failed to use MSXML, I tried a lot of thing to make it work from changing MSXML.DLL and testing different version of MSXML, using MSXMLHttpServer and all the things you may think of, I somehow ate MSDN website but didn’t find anything helpfull.
Now I am looking for other ways of calling a SOAP webservice, someone said you may post your XML to web method address by parsing and using a query string, But I didn’t succeed to do so.
I can also negotiate via TCP/IP, Can I send my XML to a web service using a TCP/IP connection?
If there is any other way that do the job I really appreciate it.
Currently I am connecting Magik to a Java application and when I need to call a web service I send my request to that Java application (there is a Jar file which creates a data-bus between a Magik session and a Java Application) I have also wrote the Java part using Axis technology. But this is a very hard job and I should change a lot of things to only keep my project up and match with a small change in web service that I consume.
Using MSXML were so easy formerly, sadly it does not work now!
First note that you can not use GET to call SOAP web services only POST will work with SOAP, GET can be used for REST but you mentioned SOAP only.
I can introduce you two method that you may use to call a web service instead of your MSXML which does not work anymore.
Using Test Form (Web Service Test Page)
You may ask your .Net web services provider to create a test form for his own web service and you create a query string which suppose to emulate the data on the form, actually you are using the web services tester page to send your data via query string to it and it will complete the rest for you.
Using TCPIP
use a TCP/IP Connection, in this method you need to create a header above your xml to set the parameters that a web service consumer should fill (remember MSXML and Content-Type, Content-Length, SOAPAction, Host, …….)
then translate your string to a byte vector since all programming language which can create a TCPIP Socket just accept a byte vector while inputing or outputing data to that connection. after translating the string you are ready to send the data to your web services address.
take a look at the following example of how you may create a string to send to a TCPIP socket.
POST /globalweather.asmx HTTP/1.1
Host: www.webservicex.net
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.webserviceX.NET/GetCitiesByCountry"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xmlns:xsd=http://www.w3.org/2001/XMLSchema
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetCitiesByCountry xmlns="http://www.webserviceX.NET">
<CountryName>Egypt</CountryName>
</GetCitiesByCountry>
</soap:Body>
</soap:Envelope>
You may send above string to http://www.webservicex.net/globalweather.asmx
You may check to following link if you need detailed information about how to consume a web service using TCPIP
http://www.codeproject.com/Articles/312530/Calling-Webservice-Using-TCP-IP-from-any-Programmi

SOAP message using namespaces

We are designing a Web application which is invoked by an external system. We are going to receive a Web service from an external system which looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tis="http://schemas.tis.com/1.2/" xmlns:der="http://schemas.tis.com/DataProvisioning/">
<soapenv:Header>
<tis:SessionId>99999999</tis:SessionId>
</soapenv:Header>
<soapenv:Body>
<tis:Create>
<tis:MOType>SPPM#http://schemas.tis.com/DataProvisioning/</tis:MOType>
<tis:MOId>
<der:codex>12345677</der:msisdn>
</tis:MOId>
<tis:MOAttributes>
<der:createSPDD ProfileID="1" Action="createData">
<der:TechProduct Action="add" BarCode="15">
<der:Arguments ArgName="arg1" ArgType="string" ArgValue="1"></der:Arguments>
<der:Arguments ArgName="arg3" ArgType="string" ArgValue="2"></der:Arguments>
</der:TechProduct>
<der:TechProduct Action="delete" BarCode="21">
<der:Arguments ArgName="arg1" ArgType="string" ArgValue="1"></der:Arguments>
<der:Arguments ArgName="arg3" ArgType="string" ArgValue="2"></der:Arguments>
</der:TechProduct>
</der:createSPDD>
</tis:MOAttributes>
</tis:Create>
As you can see this SOAP Envelope we will receive contains namespaces in it. Up to now my Web services applications have been coded using JAX-WS and bottom-up approach (just adding #WebService and #WebMethod annotation to classes). What is the correct way to design a Web service that needs to receive a message based on namespaces ? Should I design first the WSDL ? I cannot see how to collect attributes which are in the Header or Body such as MoType or MoId. Any help ?
Thanks a lot
From your question it is tough to understand whether you want to expose a web service or you want to consume one. If you want to expose a web service with this structure and namespace you can choose bottom-up or top-down approach. Using top-down approach you will create
WSDL (here clearly you can mention the namespace for the service related details)
Schema (define the namespace for request and response elements)
Generate the Java classes from the WSDL and Schema.
Write the implementation for the Web Service interface.
If at all you want to consume the service then no need to write any WSDL. Get the WSDL and Schema(if any) from the service provider, Generate the Java classes from the WSDL and Schema received. You dont have worry about reading the values based on namespaces, the jaxws framework will do it for you.
Google the steps to consume a jaxws service.

WSO2 ESB - How to build soapenv:Body for remote service call

I have the WSDL file of the remote web service I need to call from a proxy service in the WSO2 ESB and would like to know if I need to construct the soap:Body's elements manually through XSLT/Enrich or there is a way to generate the soapenv:Body's contains from the WSDL and maybe replace '?' for the values.
For example, if you've used soapUI before you'll know that when you import a WSDL file in a project a soapenv:Envelope gets generated automatically with all the XML elements and question marks for their values. Same goes for the TryIt tool in the WSO2 ESB.
Here is an example of an auto-generated soapenv:Envelope in soapUI after importing WSDL:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:abc="http://abc.com/">
<soapenv:Header/>
<soapenv:Body>
<abc:RegisterCandidate>
<abc:NameFirst>?</abc:NameFirst>
<abc:NameMiddle>?</abc:NameMiddle>
<abc:NameLast>?</abc:NameLast>
<abc:PhoneHome>?</abc:PhoneHome>
<abc:EmailAddress>?</abc:EmailAddress>
<abc:Address1>?</abc:Address1>
<abc:Address2>?</abc:Address2>
<abc:City>?</abc:City>
<abc:State>?</abc:State>
<abc:ZipCode>?</abc:ZipCode>
<abc:Country>?</abc:Country>
</abc:RegisterCandidate>
</soapenv:Body>
</soapenv:Envelope>
Is this possible in the Proxy Service through any of the mediators available to read a WSDL and generate soapenv:Body with its XML tags (in the code above it would be abc:RegisterCandidate with its children)? I've done it with the use of the XSL templates, but it's manual and not very elegant.
I've found a few articles/blogs online about writing proxy services in the WSO2 ESB that call remote web services and what the developers were doing in there was to insert the XML elements needed in the soapenv:Body with the use of XSL templates to have the correct/full SOAP message that is then sent (send mediator) to the remote web service server.
Thank you.
There is no way to generate the soap body from the remote service's wsdl as in your requirement. But there is an easier way than using xslt. That is to use the payload factory mediator. You can define the payload and assign values using xpath as shown in the sample.

Is it possible to have multiple xsd mappings in a webservice?

I'm new to web services and I'm facing a design issue where we want to create a web service (preferably SOAP based) which will receive 2 parameters:
a string variable (Client Name);
XML data.
There are currently 2 different consumers of this web service but their number will increase. All consumers have separate XSD data that they will be sending, for example:
Consumer1:
<ConData>
<Customer>
<FirstName>FirName</FirstName>
<LastName>LasName</LastName>
</Customer>
<Acocunt>
<Number>112971</Number>
</Account>
<Order>
<OrderNum>0092123</OrderNum>
</Order>
<ConData>
Consumer2:
<ConData>
<SysData>
<CustomerFirstName>Name</CustomerFirstName>
<CustomerLastName>Name</CustomerLastName>
<AccountNumber>Au1o2n</AccountNumber>
<OrderNum>koo912</OrderNum>
</SysData>
<ConData>
This web service is supposed to take the XML data from these clients and store it into the database based on the consumer name. There is no processing required on our end for validating the XML as such, we just take it and store it in the database.
As a good design though, I'd like to define my web service with explicit parameters. The problem is that since their XML data format is different I'm not able to use a single XSD schema as a parameter in my WSDL. I can think of 2 options to address this:
1. Let them pass XML data as String in my web service instead of XSD mapping parameter. Though this is a valid approach, it seems like a bad design based on what I've read so far on the forums as it voids validation and needs lots of manual marshaling and unmarshaling and other problems. Plus my WSDL will not be able to define to my clients what format is expected etc.
2. Create 2 separate web services which will handle different individual consumers with their own XSD's. This again seems less viable since in future if we add more consumers we will have to add new web services with duplicate code for the same operation etc.
I was looking to see if there is a way to define multiple XSD's in a single web service WSDL or maybe a better way of solving this problem.
On a side note, I'd prefer to have a SOAP based web service but if this problem gets resolved using a RESTful web service in a better way then I can consider that as well.
You don't need to have a different web service or skeleton for each client, you just need a different WSDL.
Forget about sending this XML parameter as string, it has disadvantages that I won't repeat here since you already read about it too. So you need to send it as XML.
To keep it into one web service, you create the web service so that it accept any XML as input (type <xsd:any> for the parameter). Type <xsd:any> will mean any kind of XML, but at least it would be XML that you can validate for structure, for starters.
This simplifies versioning of your web service as you don't need to change the code when adding another XML type of input but unfortunately you lose strong typing for your web service and the WSDL generated for the web service will not state anything about the structure of the XML it's expecting (any XML is too vague). Your web service skeleton will be created with a type like Object, XmlElement, XmlDocument or whatever in your code. And the same will happen with all your client stubs.
But for your clients this can be fixed from the WSDL by providing each client with a different WSDL.
For that you create a WSDL of your web service with common content for all clients, except the <types> section, and then merge this common WSDL for each client with their own XML Schema. You will then expose each WSDL on different URLs for each client.
Now the clients will be able to generate strong typed stubs based on their own particular WSDL.
When a client makes a call to your web service, you identify the client XML Schema and use it to validate the XML parameter and see if it's the expected content.
And if the above seem to much, then you can always choose a loosely typed RESTful web service. Whatever solution you choose though, just make sure that you validate the incoming XML using the schema of the client that's sending it.

Send/Receive a SOAP request using SPRING JAVA

I am new to Spring web services. I am going to create an xml request, and send it as a SOAP request to a web service and receive the response.I read different documents but still confused as I could not find a working sample yet.
I know that I should use WebServiceTemplate and WebServiceMessageSender, SaajSoapmessageFactory (please let me know if I am wrong) but not sure how to use them.
Do I need WSDL? if yes why?
If you have any sample code please send me to get clear on it.
Thanks
If you want to send SOAP requests, you would like to be a SOAP client. Seems like you want to use spring-ws project. Check out their great documentation on the client side. The same documentation will guide you through the process of creating a server. There are plenty of examples and ready-made configuration snippets waiting for you.
Spring-WS is built on top of XML Schema description of your message, so you will need WSDL to generate e.g. JAXB models of your requests and responses.
AFAIK, for "web services" , the WSDL file is the machine blueprint of the "ports" as they are called However! ports in WSDL "means" java language(or any other programming language used with a routine or sub or procedure or function) method and has a specific naming scheme associate the .wsdl xml file(template of the service). Each WSDL port(language method) has specifications of return value and data specifications for how to feed it arguments and their type values.