Client Executable path from webservice - web-services

I have a webservice which my windows application use as "Service Reference"
My program has more than 1500 clients and all clients calling same exe file (such as \\myserver\c$\myapp\myapp.exe)
I want to add a control into my webservice functions for check client executable path and i prevent calling a function when executable path is different than \\myserver\c$\myapp\myapp.exe
maybe
<WebMethod()> _
Public Function DoSomething() as string
if GetClientExePath <> "\\myserver\c$\myapp\myapp.exe" then
return nothing
else
return "helloooooo"
endif
end function
public function GetClientExePath()
return clientexepath
end Function
i can get client IP adress. But as i said we have more than 1500 clients i can't store their ip adresses.
Thanks inadvance.

Related

How to get your public ip address using Qt c++

I'm writing a gui for an net address etc. calculator. All the coding is done but now i want to have a button that will get your computer's ip address. I was looking for a solution and saw various posts on stackoverflow but none of them work for me...
Edit: this piece of code worked for me
QTcpSocket socket;
socket.connectToHost("8.8.8.8", 53);
if (socket.waitForConnected()) {
QString text = socket.localAddress().toString();
ui->ipAddress->setText(text);
} else {
QMessageBox msg;
msg.setText("Couldn't connect to the DNS server! No internet connection...");
msg.setWindowTitle("No internet connection");
msg.setIcon(QMessageBox::Critical);
msg.exec();
}```
I think the class you are looking for is the QNetworkInterface class.
From the man page:
The QNetworkInterface class provides a listing of the host's IP
addresses and network interfaces.
For example, calling QNetworkInterface::allAddresses() is a quick way to get a list of all the IP addresses on your machine. As for which one is the "public IP address", that's not a well-defined concept. On most modern consumer setups, it's arguable that there is no public IP address, as consumer PCs are typically hidden behind a NAT layer, and as such the only public IP address is on the network router, not on the user's computer itself.
You can use QHostInfo for this purpose. Ex;
auto list = QHostInfo::fromName(QHostInfo::localHostName()).addresses();
I am using following code snippet in my current project to get ip address. And it is working fine both on Desktop Linux and Embedded Linux. device is network interface name like "wlan0", "eth0" etc. It returns QNetworkAddressEntry which contains both ip and netmask. Use ip() function get ip address. Usually the first address entry is non-virtual one, so that's why am getting the first one.
const QNetworkInterface& networkInterface = QNetworkInterface::interfaceFromName(device);
if (networkInterface.isValid())
{
const QList<QNetworkAddressEntry>& addressEntries = networkInterface.addressEntries();
if (!addressEntries.isEmpty())
return addressEntries.front();
}
return QNetworkAddressEntry(); // could not found, invalid adress entry
Don't forget to add QT += network to your pro file.
Using QNetworkAccessManager, you can tap this free REST api: https://www.ipify.org/
That supports various options, such as returning the results in json. If you simply get that url, it will respond with the ip address you are most likely hoping to get back, in a raw format (i.e. a naked string).

Is it possible to compile a static library with an external dependancy that is unresolvable at compilation time?

I've created a web server using C and C++, which works in the following way:
First, it initialize the socket for the connection.
Then, when the server receives an HTTP request, it calls a function that will retrieve the data form the request, and create an object which will parse the incoming request. (The object contains the request's parameters and headers).
Then, it calls a function named HandleRequest, and gives him the object created. The object's type is Request, which I wrote myself.
The HandleRequest function will analyze the request, generate an HTML document, and returns the whole document as a string.
Finally, The server takes the string returned by the HandleRequest function and send it back to the client.
Now, if I want to create another site, the only code I will have to changed is the HandleRequest function.
My point is I want to pack the server itself in a static library, and then when I want to make a new website, I only have to write the HandleRequest function and link the static library when compiling to make the server.
Of course, when I try to do so, I have the error
undefined reference to 'HandleRequest'
So is it possible to make the library compile, knowing that a function has its code written outside of the library ?
Edit: I tried to compile the .cpp file with without the -c option, so that the library already have the linking done. I am aware that with the -c option, everything works fine.
Also, I tried to put
extern std::string HandleRequest(Request request);
before the function that calls HandleRequest but it didn't worked.
Quick and easy solution
Make HandleRequest a global variable that’s function pointer:
std::string (*HandleRequest)(Request);
You can move the functionality of the old HandleRequest function into something like DefaultHandleRequest, and you can even initialize the function pointer using the DefaultHandleRequest:
std::string DefaultHandleRequest(Request request)
{
// stuff
}
std::string (*HandleRequest)(Request) = DefaultHandleRequest;
If you do this, you won’t have to change any other code, but you’ll be able to update HandleRequest whenever you like.
More thorough solution
We can make this solution much more general, enabling you to have multiple servers running in the same program.
In order to do this, make a Server class, which acts as the server. An instance of this class will act as your server. Have Server store a std::function<std::string(Request)> that handles incoming requests. You can assign or update this at any time, as necessary.
Design Server so that there can be multiple instances at once, each representing a different server/service with it’s own HandleRequest function.

Windows RPC object marshalling

I'm trying to use Windows RPC for communcation between two processes (C/C++, 32bit, Win7).
I've followed the example here Instruction to RPC and successfully got RPC to work. Now I have difficulties getting the proxy / stub thing to work too.
The IDL file looks like this:
[ uuid(3cb112c0-688a-4611-83b6-31d33d87ea28), object ]
interface IDemo : IUnknown
{
HRESULT ThisIsAMethod([in, string] const char* test);
}
[ uuid(60ad6a21-ba49-483a-b0a2-faa5187b8299), version(1.0),
implicit_handle(handle_t hDemoBinding)]
interface IDemoRPC
{
void SimpleTest();
void GetDemo([out] IDemo** service);
void Shutdown();
}
I can invoke SimpleTest() remotely on the server from the client. Works just fine. But GetDemo() gives me an access violation when the server 'returns' something else than NULL.
Here's what I've done:
Build a DLL based on the generated demo_i.c, demo_p.c, dlldata.c. With REGISTER_PROXY_DLL set and a def file containing the five private entries. I've registered it with regsvr32 (the one from WOW64).
Created a DemoImpl class in the server process that extends IDemo and implements ThisIsAMethod as well as AddRef and friends.
Implemented GetDemo(IDemo** service) with a one-liner *service = new DemoImpl();
When I invoke GetDemo from the client process, the server process terminates with an access violation (0x00000014). The stacktrace shows that it happens in a separate thread deep within rpcrt4.
I would have expected that the thing returns a proxy to the client.
I have the suspicion that I'm doing something fundamentally wrong here. For one thing, I can't find an example where instances of interface-objects are created with new. There always some some magic with CoGetClassObject or something. No clue how these functions should know where to find the implementation.

Using a HTTP Module on a Virtual Directory in IIS

I have a default website in my IIS where I have created one virtual directory "wsdls".
I would want to gather statistics on how many requests are triggered to my virtual directory. This would need a request interception at web server level and gather statistics. "HTTPModule" was one of the many solutions I have considered which is suitable for such scenario. Hence I have started building one.
For testing purpose, I wanted to create a HTTP Module and apply it on a particular extension files (say *.wsdl) and on every GET request of any .wsdl files in this virtual directory, I will want to redirect the application to "www.google.com". This would demonstrate a good example of how HTTP Module can be used and deployed on IIS.
HTTPModule which is written using Visual Studio is shown below,
namespace Handler.App_Code
{
public class HelloWorldModule : IHttpModule
{
public HelloWorldModule(){
}
public String ModuleName{
get { return "HelloWorldModule"; }
}
// In the Init function, register for HttpApplication
// events by adding your handlers.
public void Init(HttpApplication application){
application.BeginRequest +=
(new EventHandler(this.Application_BeginRequest));
application.EndRequest +=
(new EventHandler(this.Application_EndRequest));
}
private void Application_BeginRequest(Object source,
EventArgs e)
{
// Create HttpApplication and HttpContext objects to access
// request and response properties.
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
context.Response.Redirect("www.google.com");
}
private void Application_EndRequest(Object source, EventArgs e)
{
//Nothing to be done here
}
public void Dispose() { }
}
}
Now I have done a build of this project for x64 version and I am able to browser successfully the "dll" file. Now I have to register this dll in IIS and whenever I try to access the *.wsdl files, the requests automatically divert to "www.google.com". Here is the next step I have done,
Then I have enabled the Handler mappings as shown below,
I am assuming that is it!! Nothing more to be done. I should be able to intercept the requests for all HTTP requests which are of the form "*.wsdl". This means whenever I access any wsdl from the server, control should be going back to google(Because of the logic written in begin request ). But unfortunately, I failed in achieving it. What can be done here?
One thing I noticed is that when you are trying to redirect to an external URL use
http://
So change
context.Response.Redirect("www.google.com");
to
context.Response.Redirect("http://www.google.com", true);
I could solve the problem what I am facing and below are the observations which were missing in my understanding and which helped me in solving my problem:
Locating proper web.config file :
Every website in IIS will be having a web.config file to have control over the application.
Since I am working with "Default Website", this refers to the directory "C:\\inetpub\\wwwroot"
There will be a "web.config" file which would be present in this director. Please create it if not already present.
Modifying web.config :
Once you have identified the file which needs to be modified, just add necessary module configuration to web.config
In this case, we would want to add a Module to the default website, the probably setting would be shown below,
Adding contents to bin directory :
Now if you try to run the application, the IIS would not find any dll or executable to run and hence we would need to keep the executables at a particular location.
Create a director if not already present with the name "bin" at the root of the directory and place all the dlls which you would want this website to execute. Sample shown below,
General Points to be considered:
Proper access must be given for the folder which consists of dll.
It is ideally not suggested to modify the entire website. It would be ideal if one works only on their web application.
If web.config is not found, we can create one.
If bin is not present in the web root directory, we can create one.

How to use web service Soap Client method with Xamarin

I have added my web service Url to my application through the steps of "Add Web Reference" with the name of "SOAPNyd" in Xamarin Studio
Now I need to connect my web Methods, I see my web referenced methods under Web Service folder but can not connect to them and need know how to call , use my methods.
Could anyone show me one example with while loop to write down its all data to the Console please. Thank you.
here is one of my methods which returns all brands that I have at Data Base first value is empty second value is my pasword dont worry about parameters
public string getMarkalarlist(string s, string key) {
getMarkalarlistRequest1 inValue = new getMarkalarlistRequest1();
inValue.s = s;
inValue.key = key;
getMarkalarlistResponse1 retVal = ((WebDBServicesHttpGet)(this)).getMarkalarlist(inValue);
return retVal.#string;
}
a piece of my need
http://www.nullskull.com/a/10476774/consuming-web-services-using-xamarin.aspx