title: Powershell: invoking New-WebServiceProxy ruins following Invoke-WebRequest
body: <p>The story so far: i'm writing a 'create-new-user' PoSh script, among all else i need it to:</p>
  
  <ol>
  <li>create <strong>WebServiceProxy</strong> object as variable (since Cisco UCM we use utilizes SOAP requests to interact with it)</li>
  <li>pull a PHP script on our Intranet website to sync it with Active Directory once the user is created, the easiest way is AFAIR <strong>Invoke-WebRequest</strong> commandlet.</li>
  </ol>
  
  <p>So now it looks like this:</p>
  
  <pre>
  $MyCreds = Get-Credential -Message "Specify your password" -Username $($env:username)
  $AXL = New-WebServiceProxy -Uri $("\\server\smbshare\AXLAPI.wsdl") -Credential $MyCreds
  ...
  Invoke-WebRequest -Uri "https://intranet.company.com/ad_sync.php" -Method Get</pre>
  
  <p>What I found out is that invoking WebRequest <strong>before</strong> creating an WebServiceProxy object succeeds, however invoking WebRequest any time <strong>after</strong> fails with the following error:</p>
  
  <pre>Invoke-WebRequest: The underlying connection was closed: An unexpected error occurred on a send.</pre>
  
  <p>I have no experience with .NET, classes and such stuff so perhaps i'm wrong in my assumptions but for now i'm trying (and failing) to find out if this behavior is expected? Basic logic suggests that creating a variable shouldn't affect invoking simple requests, but still it does. So, i'd be grateful for a link to read which explains how-it-works.</p>
  
  <p>And one more, the main question - is there a solution or at least a workaround?
  My theoretical suggestions are like removing the WebServiceProxy object out of the way (no idea how) or using alternative way of pulling a PHP script.</p>
  
  <p>Some additional info:</p>
  
  <ul>
  <li><strong>Powershell version: 4.0</strong></li>
  <li>WebServiceProxy part is provided by a colleague so i'm not too familiar with it, just have to compose everything in one script</li>
  <li>we cannot change the order of commands due to script logic, it has to be done in this particular order</li>
  </ul>
  
  <p>Any advice on this is greatly appreciated, thanks!</p>