Search code examples
c#windows-servicesexchange-serverexchangewebservicesews-managed-api

How to specify the port for an EWS Managed API service to use?


I wrote a Windows Service that monitors a specific mailbox in an on-premises Exchange Server 2016. I used .Net Framework 4.7.2 and the EWS Managed API 2.2.0.

In production, this service will be running on a client's server running Windows Server 2019. Before I could deploy this service to my client's on-prem server, they asked me which (ephemeral) ports they needed to open for my service to use. I used TCPView to see which ports my service is using locally on my development machine and noticed that the ports always change when I restart the service and also while the service is running because EWS Managed API uses a new TCP connection every time it sends an HTTP request.

I am wondering if there is a way to specify a port or several ports for my service to use when making internet calls. Any help is greatly appreciated.


Solution

  • The server port stays the same (e.g. HTTPs uses 443 by default). If you mean ephemeral ports, they are allocated by the client software initializing the connection (e.g., a browser or your EWS app).

    You need to worry about the former, but not the latter.

    For EWS (unless their on-prem server uses a different port), you will need the standard HTTPs port (443) and (if autodiscover comes from AD) the RPC/LDAP ports.