use soap services to get information - web-services

I'm new in learning Web services.
I was trying to use soap services to get a city weather from a website.
Here is the website
http://www.bom.gov.au/australia/majorcities.shtml?ref=hdr
I want to get the weather of Broome City on Friday.
While articulating my self doing this I came across two terms: EndPoint and SOAP Action
Can anyone please help me to understand these two terms ?
Is EndPoint is the URL from where I want to get information ?
SOAP Action ? What's this, why we use this and how we can use this ?
The only thing I know about SOAP services is It sends the request in xml format to server and response also comes up in xml format.(Might be am wrong)
Thanks in Advance !! :)

If you are starting fresh on web-services, I would recommend building REST service instead of soap service. That would be easier to start with.
If you go for REST service, your url would be:
http://serverxyz.com/{city}/{day}
Coming back to your questions:
EndPoint is the URL from where I want to get information ? - Correct
One web service usually has many operations which are called soap
action/soap method. Here is sample SOAP request from w3school which is also called
SOAP envelope:
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body>
<m:GetPrice xmlns:m="http://www.w3schools.com/prices">
<m:Item>Apples</m:Item>
</m:GetPrice>
</soap:Body>
</soap:Envelope>

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

Intercept SOAP request

I know this might sound like a duplicate but despite the number of result for this research, I couldn't manage to find a working answer..
I'm using a Java Web service built with Axis (the first one), running on Tomcat v5.5 and a .Net client with some Web reference (not the service reference).
What I want to do is to have a look on the outgoing request from my client, the soap enveloppe.
So far, I tried to use soapUI, great tool, helped me a lot for other thing, but the structure of my web service is quite complexe (array of complexe datatypes) so I have no idea on how I could give him some parameters, here is an exemple of the generated request :
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.main.gimaweb.itrec.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soapenv:Header/>
<soapenv:Body>
<web:televerserDocument soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<wsi xsi:type="urn:DocumentWSI" xmlns:urn="urn:DocumentWS">
<version xsi:type="xsd:string">?</version>
<documents xsi:type="doc:ArrayOf_tns1_DocumentWVO" soapenc:arrayType="urn:DocumentWVO[]" xmlns:doc="adress"/>
</wsi>
</web:televerserDocument>
</soapenv:Body>
</soapenv:Envelope>
But what i need is an array with data, so there is a lot of xml tag missing for that purpose. Maybe there is a way to generate a more complete sample request? (I don't know if I'm clear enough).
I also tried to use Fiddler, also a great tool but I never managed to get the soap enveloppe, I just got the WSDL from when I update the web reference.
I tried different kind of adresses like :
localhost:port
localhost.:port
ipv4.fiddler:port
hostname:port
But I guess the adress isn't the origin of the problem, I also used ISS Express instead of Visual Studio development server.
Finally, I tried to use some software named Membrane Moniter, but no way to get it, it's becoming quite old, maybe someone knows an alternative
Does someone have a clue on how to do this?
EDIT: And I also tried to use the TCP/IP Monitor on server side, but onece again, I only get the WSDL from the update on VS's side.. I do not really understand why.
EDIT: My Java Webservices are running on Tomcat v5.5, my ASP.Net client is a web application running on IIS Express

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

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.

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.

Can A Header Be Added & Body Modified In A Salesforce SOAP Response?

From doing some testing on SOAP requests to a webservice I created in Salesforce I note the response returned is of the following format.
Note my request function I called is GetMsgRQ
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/schemas/class/MyIntegrationServices">
<soapenv:Body>
<GetMsgRQResponse>
<result>
<acctId>001J000000leVpEIAU</acctId>
<acctName>MyTest</acctName>
</result>
</lGetMsgRQResponse>
</soapenv:Body>
</soapenv:Envelope>
Relating to this I wonder is it possible to add a SOAP:Header?
Also I note the response has created an element "GetMsgRQResponse" (adding "Response" to "GetMsgRQ". Is it possible to create/specify the SOAP:Body without this occuring? Can I just set what the whole SOAP body response will be or will Salesforce always add such additional elements as the "GetMsgRQResponse" here and "result"?
Thanks in advance for any help on this. I know I can use a HTTP Request to send a full SOAP envelope but for my requirement I need to just provide a response instead of doing so.
I don't believe you can directly add any kind SOAP headers in an Apex defined WebService methods.
If you have absolutely no other option you could construct your own custom SOAP response via a REST web service (via #RestResource annotation) but that is a pretty ugly solution.