问题
The application application I'm currently working on is required to interface with a web service using SOAP. The service providers want to restrict access to the service via a firewall using BOTH an IP address and a Port. I'm using VS 2010 and the service has been added as a .NET 2.0 Web Service.
Right now the firewall rule for my connection's port is set to 'ANY' and the service team wants to tighten it down to a specific port. I can't seem to find any way to set a specific outgoing port (port used when exiting my web server) in my service.
Is it even possible to do this?
回答1:
It is possible to do this, but it's a non-trivial customization.
- See Ways to Customize your ASMX Client Proxy for the general techniques. Near the bottom, you'll find "Heavy-Duty Customization".
- By overriding the
GetWebRequest
method, you can gain access to theHttpWebRequest
instance being used by the request. HttpWebRequest
has a ServicePoint property.ServicePoint
has a BindIPEndPointDelegate property.- Set this property to point to a method that will decide which IP address and port to use.
来源:https://stackoverflow.com/questions/13055386/define-outgoing-calling-port-for-soap-web-service-in-visual-studio-2010