I've made a WCF service. I want it's client to be able to access it from anywhere. How can I do that? Details:
- I want it to be hosted in a Windows process, not a site.
- I'm using TCP binding.
- I don't know almost anything about web hosting etc.
- It's desirable not to use IIS...
I have found many recommendations in the web, but still do not understand all the stuff. Please, tell me how to do it in details...
As I understand, it's necessary to make a global for the endpoint. I've configured port forwarding in my router to the 8000 port, but .. what's further开发者_运维技巧? What address should I enter as the endpoint address? It's now localhost:8000.
You will need a public IP address or domain name like suggested above. Find out if you already have it, if not follow the suggestions above on setting that up.
For your WCF host and client, you will need endpoint that look like this:
- Host: net.tcp://localhost:portnum/servicename
- Client: net.tcp://publicipORdomainname:portnum/servicename
You will need to make sure that your router route the port to the host PC. From the question sounds like you have done it correctly. Because the host is local, you dont have to change the endpoint to use public ip or domain name. The client needs to resolve the call to the host which resides on the remote address, hence need the addressable public IP.
You don't need IIS, you can self-host and it will be accessible via the internet.
Basically, when you self-host a WCF application, it is a server (just like a web-server such as Apache or IIS).
Here is a good website that discusses how to expose your own server to the internet.
http://www.diywebserver.com/
Keep in mind that you can skip any parts that have to do with setting up Apache, since you already have a server (your WCF application).
As I answered in this related SO link, my suggestion is based on this codeproject.com example. It works well.
you need to have a public IP and a domain name. I would suggest renting a virtual server for your service and host it in windows service.
you shouldn't be hosting with localhost:8000, because this will only be reachable on the local machine. The port forwarding won't work.
Instead use the machines network name or LAN IP.
If your service is running on IIS without any problem then you need to do following steps to access this service through internet
Suppose:
My Solution Name is SearchServiceLibrary
Interface Name is ISearch
Class Name is Search and this class implements ISearch interface
Step-1: If your PC is behind a NAT you need to forward the PORT to tell your router where it should send received requests for web services.
Step-2: To specify Domain Name/IP Address of Server in WSDL File
Update or Edit Following tag in app.config file
<serviceMetadata httpGetEnabled="True" httpGetUrl="http://DomainName_OR_IPAddress:PORT/SearchServiceLibrary.Search.svc/basic"/>
Step-3: Set Soap Location in app.config file
You need to add an End Point in your app.config file, you can do this descriptively or by using option EDIT WCF CONFIGURATIONS
<service name="SearchServiceLibrary.Search">
<endpoint address="http://DomainName_OR_IPAddress:PORT/SearchServiceLibrary.Search.svc/basic" binding="basicHttpBinding"
contract="SearchServiceLibrary.ISearch">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
OR using option EDIT WCF CONFIGURATIONS
This worked perfect for me.
精彩评论