title: Unable to connect to remote server using SoapHttpClientProtocol
body: <p>
  The client has provided me with their location to .net asmx webservice. I created a library which I use in my web application to communicate with their web service.</p>
  
  <p>In my library, I created a web reference to the asmx</p>
  
  <p>This is my code to invoke their service</p>
  
  <pre class="lang-cs prettyprint-override"><code>using (vendorproxy.vendorproxy wsProxy = new vendorproxy.vendorproxy())
  {
      wsProxy.Credentials = new System.Net.NetworkCredential(uname, pwd);
  
      using (Stream xmlStream = xmlUtil.GenerateStreamFromString(
          wsProxy.GetData(index)))
      {
          //
      }
  }
  
  public Stream GenerateStreamFromString(String inputString)
  {
      byte[] bytes = UTF8Encoding.UTF8.GetBytes(inputString);
      MemoryStream strm = new MemoryStream();
      strm.Write(bytes, 0, bytes.Length);
      return strm;
  }
  </code></pre>
  
  <p>The client developed a test app to test their service and it works. However my application when deployed on their system fails. I cannot step through the code as the client has not exposed the service outside of their network. This was developed by them providing sample output via xml file and their wsdl only.</p>
  
  <p>The exception details:</p>
  
  <pre class="lang-cs prettyprint-override"><code>at System.Net.HttpWebRequest.GetRequestStream(TransportContext&amp; context)     
  at System.Net.HttpWebRequest.GetRequestStream()     
  at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(
     String methodName, Object[] parameters)     
  </code></pre>
  
  <p>App.config of my class library that has the web ref to the service and one that does the invoking. The class library is used by my web app</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;configSections&gt;
          &lt;sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" &gt;
              &lt;section name="clientService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
          &lt;/sectionGroup&gt;
      &lt;/configSections&gt;
      &lt;system.serviceModel&gt;
          &lt;bindings /&gt;
          &lt;client /&gt;
      &lt;/system.serviceModel&gt;
      &lt;applicationSettings&gt;
          &lt;clientService.Properties.Settings&gt;
              &lt;setting name="clientService_client_client" serializeAs="String"&gt;
                  &lt;value&gt;http://localhost:2362/client.asmx&lt;/value&gt;
              &lt;/setting&gt;
          &lt;/clientService.Properties.Settings&gt;
      &lt;/applicationSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Solved:
  This worked after i modified my original code from</p>
  
  <pre class="lang-cs prettyprint-override"><code>using (vendorproxy.vendorproxy wsProxy = new vendorproxy.vendorproxy())
  {
      wsProxy.Credentials = new System.Net.NetworkCredential(uname, pwd);
  }
  </code></pre>
  
  <p>TO</p>
  
  <pre class="lang-cs prettyprint-override"><code>using (vendorproxy.vendorproxy wsProxy = new vendorproxy.vendorproxy())
  {
      wsProxy.Credentials = new System.Net.NetworkCredential(uname, pwd);
      wsProxy.URL = [correct asmx location read from config file]
      //not sure why it would not automatically pick up from config file. 
  }
  </code></pre>