0

I am using the following for standard rest calls where I can easily attach the proxy settings.

  WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true);
  WebRequest req = WebRequest.Create("http://www.contoso.com");
  req.Proxy = proxyObject;

But when i do the following call below, is there a property that i can add the Proxy settings to ?

string sourceUrl = DiscoURL.Text;
string outputDirectory = DiscoDir.Text;

DiscoveryClientProtocol client = new DiscoveryClientProtocol();
client.Credentials = CredentialCache.DefaultCredentials;

try {
      DiscoveryDocument doc;
      if (DiscoverMode.Value == "ReadAll") 
      {
          DiscoveryClientResultCollection results = client.ReadAll(Path.Combine(DiscoDir.Text, 
            "results.discomap"));
          SaveMode.Value = "NoSave";                        
      }
      else 
      {
        if (DiscoverMode.Value == "DiscoverAny") 
        {
           doc = client.DiscoverAny(sourceUrl);
        }
        else
        {
          doc = client.Discover(sourceUrl);
        }
        if (ResolveMode.Value == "ResolveAll")
          client.ResolveAll();
        else 
        {
         if (ResolveMode.Value == "ResolveOneLevel")  
            client.ResolveOneLevel();
         else
            Status.Text = String.Empty;
        }
      }
    }
    catch (Exception e2) 
    {
      DiscoveryResultsGrid.Columns.Clear();
      Status.Text = e2.Message;
    }
   

Is there a way i can attach my proxy setting to the call ?

Abbey
  • 153
  • 2
  • 11
  • As per the documentation: https://learn.microsoft.com/en-us/dotnet/api/system.net.webrequest.proxy?view=net-5.0 – Murray Foxcroft May 04 '21 at 06:29
  • 1
    Does this answer your question? [C# Connecting Through Proxy](https://stackoverflow.com/questions/1938990/c-sharp-connecting-through-proxy) – Murray Foxcroft May 04 '21 at 06:48
  • If i was to use the config option , what is the tag for networcredentials (username, pwd). Also , it may work for http requests but will it work for downloading a wsdl , making a web service call ? – Abbey May 04 '21 at 09:36
  • Yes, it will work for any request from the WebRequest instance. What do you mean by tag? Are you talking about using the default credentials instead of username and password? https://learn.microsoft.com/en-us/dotnet/api/system.net.webrequest.usedefaultcredentials?view=net-5.0 – Murray Foxcroft May 04 '21 at 09:48
  • I have just tried it by code. I set the WebRequest.DefaultWebProxy after a successful user login. I would have thought it would have been set for any request. But it doesnt seem to work for any of my SoapHttpClientProtocol calls.. The proxy is null.. Even if i explicitly set it before the call , it still give Proxy Authentication error – Abbey May 04 '21 at 10:06
  • 1
    You will need to set the proxy on other objects you create (like SoapHttpClientProtocol ) Are you maybe running in to this problem https://stackoverflow.com/questions/4180572/soaphttpclientprotocol-caches-proxy-credentials – Murray Foxcroft May 04 '21 at 11:10

0 Answers0