Deploy a callback API to a VM with IIS - c#

I am hoping to deploy a web api to handle callbacks from a 3rd party.
I'm a beginner at C#, but I've written a simple Web API using Visual Studio in order to handle the callbacks.
To test on my dev machine I click the green run button with IIS selected on localhost, and the dll is created. I can feed it some 3rd party test JSON files (using Postman) and the database is updating correctly. So far so good.
Now I'm looking at deployment to a test server, which can receive live (test) callbacks. To do this, I've run up a new VM with a public IP address, installed SQL Express and also installed IIS.
I am assuming the next step is to publish (web deploy) from VS.
But I'm becoming confused with regard to domain name, URL and IP address.
a) Do I need to register a domain name for the IP address? (There is no UI, just the callback endpoint)
b) When setting up the publishing profile for web deploy, what is the Destination URL?
There is a lot of information available on the subject, but there are clearly a few important gaps in my knowledge, and I can't seem to fill 'em.
Thanks

If I am understanding your question correctly - no you do not need a domain name to test your application. You can use a tool like Swagger to test your API. Read more here: https://www.blazemeter.com/blog/getting-started-with-swagger-ui
Good luck!

Related

how to serve .net console on Nginx?

So I got it to the stage where the .net (framework) console application could run on localhost, but the next issue is exposing it using Nginx.
I looked at many tutorials, but they all seems to be for websites. How can i make it work for a console app?
Thank you.
What do you gain from using nginx in front of it instead of just
opening the console app on port 80 (or preferably 443 witha
certificate)? You will probably need to set up nginx as a reverse
proxy for your app.
I have the console app running on port 1234 because there is already an app using port 80. To be honest, I am not sure why I am using Nginx, I just assume that's what I need, since I have the app running on localhost but I cannot access it from outside. I have set the firewall to accept that port from the domain provider side.
uhm.... what exactly do you mean by "exposing a console application"?
because what you expose with nginx - or any other webserver - is a
website. also: welcome to stackoverflow. i recommend taking the tour,
as well as reading how to ask a good question and what's on topic.
Thank you. I am probably not using the most accurate term. Basically, I just want people to be able to access my app. In my mind, I imaging there is some additional setting I need to do to have it "exposed" to the public (and that's using nginx). I can see the app running on localhost but not sure why it's not public.
please say what you expect a console app 'exposed to the public' would
look like. How would they access it? What tool on my desktop would I
start, ignore the nginx part of the discussion
So I have a loop serving some web content similar to this one.
https://gist.github.com/define-private-public/d05bc52dd0bed1c4699d49e2737e80e7
When I run it, external user should go to a website and see the page content served up by this.
If your console app is a Console.ReadLine() Console.WriteLine() type
thing the only way to expose it simply is to setup and SSH server on
your host system. Then the users need an SSH client to access it. This
is doable via web browser hosted SSH access but thats v complex
solution
You can ignore all the Console Readline and Writeline stuff.
Ok, so the solution is actually quite simple. All you need to do is forward your incoming request to a localhost using proxy_pass, as suggested by #fredrik. The following should be added to the default config file (under nginx):
server {
listen 80;
listen [::]:80;
server_name example.com;
location / {
proxy_pass http://localhost:8888/;
}
}

Application or Service to do some tasks in specific time slot

I've scenario to create an application(Windows service , Winforms app) which runs twice every day automatically on users PC. These Users are internal employees in the same network. So at morning and evening this application has to run. But it doesn't need to show any window or information saying its running. Its good to have a simple notification in system tray that its started execution.
My experience in with web application development. So I got a little stucked with these such application on deciding which is best.What my understandings are if its a standalone exe, we could ask all users to download the exe and install.
If its a windows service we may depend up on instalutil to install the service.
So I really needs an advice on this. The application is nothing, just requesting a TFS api and the resulting JSON has to store in Table. So the JSOn will be based on each user using their windows authentication.
Please suggest a good solution to achieve its the best,secure and easiest way even for non tech savvy users.
Instead of all user communicating to TFS server twice a day i guess better way is to install a service in one centralized machine which will run a window service twice a day and that machine will host that service using WCF so that other user will communicate with machine this will help you to distribute the load of tfs api. i used the same approach in my case where one machine talk to ALM and other talk to that machine to get the files.
Creating a window service is pretty simple and straight forward.
Follow the link to make one:
https://www.c-sharpcorner.com/UploadFile/naresh.avari/develop-and-install-a-windows-service-in-C-Sharp/
You can host the service in WCF using IIS, TCP, Webservice, Console application its upto you. Follow this link
https://www.codeproject.com/Articles/550796/A-Beginners-Tutorial-on-How-to-Host-a-WCF-Service
I guess i helped you :)

Can I open client's Windows Explorer from WCF?

Good morning,
I have following scenario: I have solution with two projects - first project is MVC WebClient and second one is WCF Service. I want open Windows explorer on specific location, probably through WCF. I know that it is not possible from pure client so I was thinking if WCF can does it.
Full scenario is: User clicks on button and then windows explorer will be opened.
I have tried do it on my local computer
Process.Start(path);
and it works, but what if I will host it on IIS?
Will it works?
Will it open client's explorer or server's explorer?
If first two steps will work, will I need host WCF service on IIS too or MVC client with service reference is enough?
And if this scenario won't work, can anyone help with some solution for this problem (if is any)?
Many thanks
The only way I could think of doing this purely with a browser would be to require the client to use IE and then embed an ActiveX control. The page would have to run with the highest security privileges so the ActiveX could run unimpeded. The nice thing about this is it would not require much (if any) server-side support. It would all be handled by Javascript.
Otherwise, to make it browser agnostic, you would have to have a listener app running on the client machine, probably as a service or set to start on machine boot (good candidate for the notification area on the taskbar). The listener app on the client machine could establish a connection to the server using WCF, Sockets (whatever you want really) and then when the user presses the button on the WEB application a message is sent from the web server to the client-side listening application. This of course could trigger anything you want on the client-side.
I see several complications with this as well:
1) How do you get the listener installed on the client machine?
If it's really simple you could just send the exe over with instructions where to copy.
You could build an installer or use ClickOnce to deploy it right from the website: http://msdn.microsoft.com/en-us/library/ms973805.aspx
2) Your web application now needs to communicate with a server-side component that is connected to the client-side listener. If you are already using WCF on the server this might not be too bad. If the client-side listener connects to the same web application the user is using it probably wouldn't be too difficult either (use long-polling or web sockets, etc)
3) How do you secure the client-side listener and connect the client-side "session" to the web "session" such that the user clicking on the button in his web browser sends a message to his instance of the client-side listener and not another user's listener.
These are all doable. I wrote an app that worked sort of like this several years ago. There were definitely challenges but we got it working and it has been stable for several years now. We used WCF.

Test subdomains on local webserver in VS

I am still experimenting with Azure multi tenant development. I now have my first trial thingy, but in order to use subdomain names (customer.site.com) I need to switch my Azure website to shared/reserved. Since I am still experimenting, I rather not start paying for Azure. Is there a way around this? Or, is it possible to test the multi-tenant part in my local visual studio webserver?
No, you can't have custom domain names with FREE websites.
But what you could do, is to switch the tenant recognition from sub-domain to a path. So instead of having tenant10.site.com/ you would have mysites.azurewebsites.net/tenant10/. That would basically be just a change in URL Rewrite rules - which I think is the right way to handle multi-tenancy recognition at URL level. And URL rewrite is supported in Azure WebSites as well Azure Cloud Services.
Testing the multi-tenancy locally is even easier. You just open your hosts file (in a typical windows installation it is located in c:\windows\system32\drivers\etc\hosts. Just add entries for all (sub)domains you want to test, and map them to 127.0.0.1. Something like:
127.0.0.1 tenant1.mydomain.com
127.0.0.1 tenant2.mydomain.com
127.0.0.1 tenant15.mydomain.com
...
Then, run your project with F5 like you would normally do and manually type in the new address in browser's address bar: tenant1.mydomain.com.
However first launch the project with F5 to check the real IP address of local development fabric, because sometimes it may not be 127.0.0.1, but 127.0.0.8 or something else. The IP address that is used in your browser's initial launch is the IP Address you have to fill in your hosts file.
However, if you work with real (sub)domain names in hosts file, do never forget to remove the entries from it, as you will never reach the real Internet sites.

WebService: Difference between my pc and server

I have a bug where special characters (danish 'ø' in this case) are shown correctly when running locally, but wrong when the code runs on a server (I get a pipe '|'). I was trying to solve this today, but I did not have access to the server, other than updating the code files. I will limited access monday, so I can at least write intermediate results to a log file, but to be prepared I thought I'd ask for suggestions here.
Program flow:
A C# test calls my own web service via a WebRequest.
This web service calls an external web service via another web request.
When running my own web service locally I get correct results returned from the external web service.
When deploying the code to the server the external web service returns an error; it didn't find the word I was searching for. Except that I entered 'Bøssemagergade', but the word it complains about is returned as 'B|ssemagergade'. What can cause this difference? AFAIK the server runs with the exact same regional settings as my local machine.
I'm sure this is common stuff, but I haven't been doing web services before (I do feel at home with C#/.NET though, and know about encodings etc.).
Thanks!
You need to check your data at every stage in the process. Make sure you understand which encoding you're using (try to avoid using Encoding.Default) and verify the binary data going across the wire with something like WireShark.
See my debugging unicode problems article for further information.

Categories