Deploy WCF service - c#

I need to deploy a WCF service where the user specifies some configuration data.
Let me explain: the service connects to a web server and the user should specify IP and port of that server.
How could I do it?
A solution could be to develop a tool which allows the user to create the configuration file and to "say" the service where to get it back.
So basically create installation packages with the service
and the configuration file.
Thanks
Federico

You can change the service endpoint IP address, etc. at runtime in the client program, so popping up a dialog at any point before connecting to the web service and asking the user for the IP address, etc. should work just fine, no need to jump through install package/config hoops unless you want to. Here's some code that I yanked from one of my blog posts that does pretty close to what you need:
ServiceReference1.Service1Client oneService1Client = new ServiceReference1.Service1Client();
oneService1Client.Endpoint.Address = new System.ServiceModel.EndpointAddress(
new Uri(oneService1Client.Endpoint.Address.Uri.ToString().Replace("localhost", "127.0.0.1.")),
oneService1Client.Endpoint.Address.Identity,
oneService1Client.Endpoint.Address.Headers);

Related

Can't find the device thats self hosting a web api

I'm using Owin and Topshelf to selfhost an ASP.net Web Api.
I am able to access it through localhost and 127.0.0.1 on the device that is self hosting it.
The idea is that any device that comes onto the network and has my computer or mobile application installed is able to communicate with that web api to request/update/remove data from the database hanging behind.
The issue i am having is that i have no way of finding out on what internal ip the service is actually running. I have no control/view over the network that it's installed onto (except through my code), this means i don't know what the ip or hostname might be, only the port number (on any other device that isn't hosting it).
I tried adding custom url's like shown below
StartOptions options = new StartOptions();
options.Urls.Add("http://localhost:6969");
options.Urls.Add("http://127.0.0.1:6969");
options.Urls.Add(string.Format("http://{0}:6969", Environment.MachineName));
options.Urls.Add("http://+:6969");
Obviously localhost and 127.0.0.1 won't work for a remote device on the same network. The issue with the MachineName is that i don't have a say in the name of the machine either, meaning this could be anything. I assumued the wildcard would allow me to send a request on port 6969 and the host would catch it, this was sadly not the case.
This leaves me in a bit of an issue, i now have a self hosted Web api, on a machine with a random ip and name, and it needs to be accessed by other devices on the same network, The users are not able to manually enter ip, and i can't force a name onto the host computer. This all leaves me in a situation where im not sure wat else i could try, or if its even possible to reach the host computer without human interference.
Edit: I did come across something along the lines of a
network broadcast address
Which should in someway allow me to send out a message from a device, and let the server respond with its ip. Not sure how i would apply this to my self hosted web api though.
Basically, the idea is to have your web API application register its address to a service, such as DNS, which may be updating the IP address of a DNS A record. Then clients will query this service or DNS, to resolve the address to your application.

Can't access a basic Fabric Azure WebAPI OWIN stateless service

After following the tutorial, I've succeeded running it on localhost:8534/simpleprime/api/values/* having the same result as the tut.
Later publishing the solution to a remote cloud cluster, I couldn't access it using www.clusterurl:8534/api/values, timing out each time. Even though I got reassuring event diagnostics from Visual Studio during the deploy.
I've also tried each of the nodes seperetly, going to
http://node_ip:8543/simpleprime/api/values, without any luck
simpleprime is the appRoot
If you want to access your service with OWIN listener on Azure, you should define ports that will be used by your application for the LoadBalancer during cluster creation.
If you for some reason forgot you can do it later by:
SERVICE PART
Go to PackageRoot/ServiceManifest.xml of your service with OWIN Listener
Define your endpoint directly (so SF will use your definied port number) (in my example 8081)
Re-publish application to Azure.
AZURE PART
Go to Azure Portal
Find the Load Balancer that is assigned to your SF (LB-nameofyourSF-namofNodeSet)
In LoadBalancer settings go to Probes and add new probe like on the image below with your Port defined in ServiceManifest.xml (on my example 8081) and Protocol TCP
Add new Load balancing rule with your port and probe defined earlier and the correct port mapping (in my example 8081):
Save and now you should be able to access your service on Azure via browser.
Finally solved it, inside the service port config (a.k.a ServiceManifest.xml) there is a port setting. After changing it to 19080 - the default http port my cluster was listening to, everything started working.

Expose WCF service hosted in IIS to users

I have a server physically located in the US. The OS is Windows Server 2008 R2 SP1.
I create a WCF service and host it in IIS on the server.
Now, while I'm physically in Germany, I want to write a WCF client to the WCF service. First of all, I need to create a WCF client proxy.
All the tutorials I've seen imply that the WCF service and WCF client are located on the same machine. I.e., the tutorials use "localhost" everywhere. In my case it doesn't work.
I know the IP of my server but I don't know what settings should be done to allow any programmer to use the WCF service. I guess it requires special customization of the endpoint at the WCF service and some settings at the IIS to make the WCF accessible by anybody.
Can you please give a piece of advice in this regard?
Thanks for any suggestions!
Two approaches are available :
Create a service reference using the add reference , enter your service address should be something like : http://IpAdress/service.svc , or if you have your wsdl file on your local disk , just enter your wsdl file location in the add service address bar. This will generate the proxy class.
If you have the service contract(interface) just do it programatically using ChannelFactory , you must know your binding and endpoint address as well.
If have any questions you're welcome

Internal communication between a service and multiple user applications WCF C#

I'm currently working on a project in c# where I have a service running as LocalSystem, and a user application (tray app) running for each logged on user.
I need to have communications between the two.
Initially I've set up an endpoint using NetTcpBinding on the service for the clients to connect to and supply their username. Thereafter the clients each set up an endpoint themselves as such; net.tcp://localhost:5001/UserApp/'username', with port sharing enabled. The service can then connect to that endpoint, knowing the username.
Though, when trying to get the program to work well with UAC I ran into some issues. Port sharing with UAC enabled requires the user to be registred in <'allowAccounts> of SMSvcHost.exe.config, and even though I've added the user, I still get the following errror when trying to register the endpoint;
The service endpoint failed to listen on the URI
'net.tcp://localhost:5001/UserApp/myuser' because access was denied.
Verify that the current user is granted access in the appropriate
allowAccounts section of SMSvcHost.exe.config.
I've also tried switching to NetNamedPipeBinding, which works well when hosting the user application. But when using this binding the service can not access the endpoints opened by the clients.
So, basically I need a way for a single service to provide an endpoint for multiple user applications on the same machine, and the service to be able to connect to and send event updates to multiple user applications.
Any suggestions?
in this case I would think about using callback channels instead of opening new services on the client (ok - it's almost the same but it fit nices into the WCF framework and setting).
You can read about this here: What you need to know about One-Way Calls, Callbacks, And Events
You may want to also look Duplex services, in particular the 'wsDualHttpBinding'. It is designed to do just want you are asking... to allow both the service and client to send messages independently to each other.
http://msdn.microsoft.com/en-us/library/ms731064.aspx

How to retrieve PC name of client from C# webservice

I have a C# web service running on a separate server machine. I would like to be able to retrieve the client machine name when using a specific method on the web service. I have searched online and people have mentioned that this would be difficult to retrieve client machine names if the clients were connected to a router.
Update: If there is no way to get around the router issue, how would I be able to get the client's information (e.i. ip address, machine name, .... anything)
HttpContext.Current.Request.UserHostAddress
HttpContext.Current.Request.UserHostName
I don't think this is really possible. If the user is behind a router all you're going to get is whatever the router reports.
I don't know of a way to retrieve the client PC name from the web service. However, you could send the name as a parameter to your web service. We send the value of Environment.MachineName as a parameter to one of our web services. This will make the information available on in the web service.
Of course, we only have our WinForms client accessing the web service. You may not be able to do the same thing.

Categories

Resources