http request in windows service - windows-services

How can we implement like this request:
http://nominatim.openstreetmap.org/reverse?format=xml&lat=52.5487429714954&lon=-1.81602098644987&zoom=18&addressdetails=1
in a windows service.
what we are trying to do is this:
run a request from windows service, and when we get the response back,we will save to DB?
Edit: the service is in C++ native code

Simply use the WebRequest or WebClient classes.

In native code you can use the WinINet library to make HTTP requests. The HttpSendRequest() method in particular.

Related

Post Https SOAP request for performing an action in application using robot framework

I wrote this robot framework test to post a https request to a webservice. The request body is in xml format and not in Json. I have used request library for this, but i am receiving error when i post using the code listed below.
With postman, i had send the body as raw data and got response as 200 ok, but when i try to do the same in robot framework its throwing error 404.
Please help me on this:
Is requests library relevant for post of https xml data soap request
to a web service?
Can any modification be made to below code for posting a https request
to a web service?
Is there any other library through which we could achieve calling
soap web service?
The Robot Framework Script
***Library***
Library String
Library Collections
Library RequestsLibrary
***Variables***
${user} = username
${passwd} = pwd
&{headers} Content-Type=application/soap+xml or text/xml Authorization=Basic encrypted details
${body_request} = <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://example.com/schemas</a:Action><a:MessageID>msgid</a:MessageID><a:ReplyTo><a:Address>url</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">serviceurl</a:To></s:Header><s:Body xmlns:xsi=body"></s:Body></s:Envelope>
*** Test Cases ***
${auth}= Create List ${user} ${passwd}
Create Session alias=proc url=url headers=${headers} auth=${auth}
Sleep 5
${resp2} Post Request alias=proc uri=url data=${body_request} json=None params=None
headers=${headers} files=None allow_redirects=True timeout=None
Should Be Equal As Strings ${resp2.status_code} 200
Log To Console ${resp2.status_code}
Answers to your question mentioned below,
Is requests library relevant for post of https xml data soap request to a web service? - yes, it can be used. however, there are better ways to achieve the same, see the solution below.
Can any modification be made to below code for posting a https request to a web service? - I think it is nothing to do with https, since 400 is bad request, you need to look at the body.
Is there any other library through which we could achieve calling soap web service? - SudsLibrary.
Although, you can make use of requests module to achieve your solution,
My philosophy when making use of robotframework is "SIMPLY MAKE USE OF EXISTING LIBRARIES" which is already verified. Please do not spend time to solve the problem keeping the thought process of "using a language".
Solution
Please make use of "SudsLibrary" library for SOAP requests, look at Keyword Documentation for your reference.
SudsLibrary is a library for functional testing of SOAP-based web services. SudsLibrary is based on Suds, a dynamic SOAP 1.1 client.
pip install robotframework-sudslibrary3
When you use the above library your code would be something similar to the one seen below,
*** Settings ***
Library SudsLibrary
Library Collections
*** Test Cases ***
Sample Testcase On SOAP
${BASE_URL} Set Variable http://www.someservice.com
${SERVICE} Create Dictionary
... name=someservice
... wsdl=someservice.asmx?WSDL
${PORT} Set variable SERVICE_PORT
${METHOD} Set variable CALLSOMEACTION
Set Binding SOAP-ENV http://www.w3.org/2003/05/soap-envelope
Create Soap Client ${BASE_URL}/${SERVICE.name}/${SERVICE.wsdl}
Set Port ${PORT}
Set Headers Content-Type application/soap+xml
Set Headers Authorization Basic encrypted details
Set Headers Soapaction ${EMPTY}
Set Headers Action "${BASE_URL}/${SERVICE.name}/${METHOD}"
${result} Call Soap Method ${METHOD}

No response when calling read() method of oData model

I have a problem that no data returns when I read an OData service via ODataModel.
But when I copy the request URL directly to web browser I can get through the odata service and the results are listed. Can you please help on this issue?
This was solved because of some CORS coding in the backend services.

415 error while trying to POST or PUT to a RESTLET service

I'm using Restlet v2.1.2 to build a Java based REST service. Everything has been working flawlessly BUT no I've run into problems while trying to PUT/POST to the service using a .Net client, which in turn uses RestSharp to talk to the service. As I mentioned various GET/PU/POST/DELETE request have all worked flawlessly but now when I try to send a "large" request I've run into problems.
I have a URI looking something like: "http://:/matches"
What I'd like to do is to provide two URI parameters {index} and {base64encoded} but as the {base64encoded} may get veeeeeery large, I unfortunately have to rely on PUT/POST in order to use the request.AddBody() method and there provide an object containing those parameters. Furthermore I set request.RequestFormat = DataFormat.Json; but when I execute the request I get either a http 405 or 415 error.
What am I doing wrong here???
I'm so sorry! I had simply overseen the fact that I had forgot to provide the "...foo(JsonRepresentation bar)" parameter declaration for the Get method!!! After adding this parameter it works like a charm:) Thanks for your reply though...:)

ASIHttpRequest call Restful web service?

Can ASIHttpRequest call Restful web service ? I knew that Restkit is good at it.
If no,any easy way to convert ?
Can we say that ASIHttpRequest is good at calling soap based web service ?
Thanks for your comments !
ASIHTTPRequest simply does a HTTP request. Nothing more, nothing less. Since REST is also just an HTTP request, you can use ASIHTTPRequest just fine with a restful web service. It doesn't do any parsing of the response, though, so if the response is JSON you still have to parse that yourself.
You can also use ASIHTTPRequest for SOAP but you have to construct the XML by yourself (or using some other library) and parse the XML response by yourself as well. For SOAP you may want to use http://sudzc.com/ instead.

How can I access/modify headers of request/reponses in a Delphi 2010 DataSnap Server

I'm in the process of building a DataSnap Server that functions as WebDAV server and I'm trying to read the request headers when using a DSHTTPService and then modify the response headers.
Can anyone point me in the right direction? I've notice the Trace TDSRequest and TDSResponse are ancestors of TDSRequestIndy and TDSResponseIndy and those components have access to the headers but am not entirely sure how to get from a TDSRequest to TDSRequestIndy.
Also I didn't think that the Trace would be the cleanest way to access the request and response, but it's the only way I've found so far.
The reason for trying to do this with DataSnap and not just straight Indy is that I'm looking to use DataSnap for other remote methods.
Maybe you should consider using TidHTTPServer and create an indy server that has many events and methods, rather than starting from DSHTTPService, including OnBeforeBind, OnAfterBind, OnHeadersAvailable... in which you have access to headers

Resources