0

Attempting to use a SoapClient like a HttpClient. I work in multiple different languages, so I apologize if my code examples flipflop between vb.net and c#.

The reason I need to target a specific IP is that I have multiple servers and want to test them individually.

This code works for the HttpClient.

private HttpClient request = new HttpClient() { DefaultRequestHeaders = { Host = "abc.google.com" } };
HttpResponseMessage responseFromApi = request.GetAsync(new Uri($"https://{server.IpAddress}/health/healthcheck.html")).ConfigureAwait(false).GetAwaiter().GetResult();

I have a SoapEndpoint that I added through the Visual Studio Service References (WSDL). I'd like to still be able to target certain IP's. This code does not work. Any suggestions?

Dim wsRate As RateUtilitySoapClient = New RateUtilitySoapClient()
Dim addressHeader = Channels.AddressHeader.CreateAddressHeader("Host", "", tbEndPoint.Text)
Dim endpoint = New EndpointAddress(New Uri(String.Format("http://{0}/SoapEndpoint.asmx", IPToTarget)), New AddressHeader() {addressHeader})

wsRate.Endpoint.Address = endpoint
Teddy Higgins
  • 140
  • 10

1 Answers1

0

Your web.config should have system.serviceModel config section with a binding. This binding should have a corresponding client endpoint config, that is where you can set any host you need.

E.g.

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IMyService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        <security mode="Transport">
          <transport clientCredentialType="Certificate" />
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="https://myservice.local.myCompany.com/MyService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService" contract="MyService.IMyService" name="BasicHttpBinding_IMyService" />
  </client>
</system.serviceModel>

Hope this helps. Good luck.

fluidguid
  • 1,511
  • 14
  • 25
  • Thanks, but it doesn't help. I need to target a specific server. All the servers are hosting the same URL, that is why I need to use an IP. – Teddy Higgins Jul 17 '19 at 18:32
  • Are you not able to use "http://127.128.129.130:8080/SoapEndpoint.asmx" instead of "https://myservice.local.myCompany.com/MyService.svc"? What error do you get if you try that? – fluidguid Jul 18 '19 at 18:05