2016-10-03 91 views
0

使用我的公網IP 151.253.XX使用公共IP

我的代碼有專用的內部IP本地Windows服務器上的Web服務器172.22.XX 我想通過SOAP進行通信和外部服務器發送SOAP請求是在C#中,我的問題在於,我的請求將與我的私有IP一起外出,因爲我的外部服務器只能從我的外部IP接收消息。

如何發送/接收來自我的外部IP的請求?

+0

如何使用HttpWebRequest發送SOAP請求? – Evk

+0

使用SoapHttpClientProtocol – Halim

回答

0

隨着SoapHttpClientProtocol,我想(沒有檢查),你可以執行以下操作:從它繼承(或任何類從它繼承,如果您有它的話),並覆蓋GetWebRequest方法,像這樣:

public class MyProtocol : SoapHttpClientProtocol { 
    protected override WebRequest GetWebRequest(Uri uri) { 
     var request = (HttpWebRequest) base.GetWebRequest(uri); 
     request.ServicePoint.BindIPEndPointDelegate += (servicePoint, remoteEndPoint, retryCount) => { 
      return new IPEndPoint(IPAddress.Parse("your external id here"), 0); 
     }; 
     return request; 
    } 
}