1

I am trying to make a Soap call to a webservice hosted by business partner. The problem I am having is that our client is hosted on a virtual PC with multiple IPs. I would like to call the hosted webservice with a different (not default) IP address. Why is that? There is VPN connection between our client application and hosted webservice but it is set up LAN2LAN between two IPs. Now I have to change local source IP address to match with the VPN requirements.

I have tried using SoapHttpClientProtocol's WebProxy, setting its value to the new IP but it does not seem to work. I am getting HTTP 404 error.

Here is some of the code:

//soapApiClient is typeof SoapHttpClientProtocol
//endpoint url -> webservice, url from appSettings
var url = SettingsProvider.ClientSapGetUserDataUrl;
soapApiClient.Url = url;

//proxy settings -> setting new IP, defined in appSettings
var proxy = SettingsProvider.ClientProxyAddress;
soapApiClient.Proxy = new WebProxy(proxy);

//credentials
soapApiClient.Credentials = GetCredentials();

I HTTP post user code and return value should be user data from SAP, currently I am getting 404 http error code. For comparison, it works like a charm from SoapUI. Maybe setting proxy is not what I am looking for? Any help would be much appreciated.

EDIT: To be more clear Currently, by default service is called from default ip 91.185.201.88. Service's IP is 10.67.145.70. I want to change it like so: service is called from 192.168.4.2 to service's 10.67.145.70.

raiden_x7
  • 71
  • 1
  • 6
  • Why not use the Computer Name instead of the IP. – jdweng Apr 17 '19 at 10:32
  • It has to be IP. I have been googling some more and have come across ServicePoint class which manages connections. Have not been able to make it work though. – raiden_x7 Apr 17 '19 at 11:27
  • If you are using DCHP the IP address can change and IP routing (including mask) may not be setup for IP addresses. Routing is done by Computer name and DNS. – jdweng Apr 17 '19 at 11:54
  • IP is static. You do not have to worry about this. The only thing missing is what I am asking for. Thanks for the heads up anyway. – raiden_x7 Apr 17 '19 at 12:04
  • The solution is to configure PC so the mask automatically choose the correct subnet. IP routing you cannot specify the subnet interface in code. The masks must be configured to choose the correct sub network. – jdweng Apr 17 '19 at 12:11
  • In this case you would make the default route mask 0.0.0.0 on 192.168.4.2 then make mask on 91.185.201.88 the following : 255.255.0.0 which is more restricted. – jdweng Apr 17 '19 at 12:22

1 Answers1

0

I finally managed to make it work. If anyone else will have problem with this, just follow these instructions.

  • Before calling remote service, you have to find service point for it. This is done via ServicePointManager like so

Example:

var servicePointUserReader = ServicePointManager.FindServicePoint(new Uri(FULLY QUALIFIED REMOTE SERVICE URL));  
servicePointUserReader.BindIPEndPointDelegate = (sp, remote, retryCount) => new IPEndPoint(IPAddress.Parse(SOURCE IP FROM WHICH YOU WANT TO SEND REQUEST), 0); 

In my example, fully qualified remote service url was something like http://65.145.63.71:8010/sapService (this is the one we are trying to call). Then I wanted to make a call from a different IP on our virtual PC which has many IPs addressed to it. You just need to input desired IP as shown in the second line of the code, for example 192.168.5.1.

Make sure you use "http://" when calling FindServicePoint with new Uri() constrcutor otherwise it will not work!

After that just proceed with the call to the service. Two lines of code, that's all you need. :)

raiden_x7
  • 71
  • 1
  • 6