Unable to call New-WebServiceProxy in a script

Hello!
I’m having an issue calling New-WebServiceProxy in a script. I get the following error.

[7:37:49 PM] [ERR] Could not load file or assembly ‘file:///C:\Users\User\AppData\Local\Temp\yd0b2elx\yd0b2elx.dll’ or one of its dependencies. The system cannot find the file specified.

The “User” is the username of the same account as the application pool identity. I’ve set the user to full admin of the server as well, no change. Using IIS to host, I’ve tried in/out process. The script is one line.

WebServiceProxy

$proxy = New-WebServiceProxy -uri ‘http://soapclient.com/xml/SQLDataSoap.WSDL

Any help would be greatly appreciated, our main planned use of PSU is to interact with Soap APIs

Product: PowerShell Universal
Version: 1.5.16

Hey @jbennett_impact!

Are you using Windows PowerShell or PS7? I know New-WebServiceProxy doesn’t exist in PS7 but just want to make sure it’s not doing some weird compatibility thing and trying to load the DLL into PS7 after running the command in WinPS.

You might be able to get a little more information from the exception by catching the error and digging into the exception and inner exceptions.

try 
{
    $proxy = New-WebServiceProxy -uri ‘http://soapclient.com/xml/SQLDataSoap.WSDL’
} 
catch 
{
    $Exception = $_.Exception
    Write-Error $Exception.Message
    $InnerException = $Exception.InnerException
    while($InnerException) { 
       Write-Error $InnerException.Message
       $InnerException = $InnerException.InnerException
   }
}

I haven’t tested New-WebSerivceProxy directly but if this doesn’t yield anything, I can spin up a job and see if I have any more luck.

Thanks for getting back to me! PSU is awesome, btw.

Environment: 5.1.17763.1852

$_.Exception gave me:

File name: 'file:///C:\Users\User\AppData\Local\Temp\tfgow4hn\tfgow4hn.dll'
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.Assembly.Load(AssemblyName assemblyRef, Evidence assemblySecurity)
   at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()
   at Microsoft.PowerShell.Commands.NewWebServiceProxy.GenerateWebServiceProxyAssembly(String NameSpace, String ClassName)
   at Microsoft.PowerShell.Commands.NewWebServiceProxy.BeginProcessing()
   at System.Management.Automation.Cmdlet.DoBeginProcessing()
   at System.Management.Automation.CommandProcessorBase.DoBegin()

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

I guess it’s creating that file temporarily each time you execute the command. When I go to look for it, it really isn’t there (or anywhere else)
New-WebServiceProxy uses the System.Net.WebClient class. I tested the code below and that works just fine.

$DotNet472OfflineInstallerUrl = "https://download.microsoft.com/download/6/E/4/6E48E8AB-DC00-419E-9704-06DD46E5F81D/NDP472-KB4054530-x86-x64-AllOS-ENU.exe"
        $DownloadDirectory = 'C:\Temp'
        $OutFilePath = "$DownloadDirectory\NDP472-KB4054530-x86-x64-AllOS-ENU.exe"

$WebClient = [System.Net.WebClient]::new()
            $WebClient.Downloadfile($DotNet472OfflineInstallerUrl, $OutFilePath)
            $WebClient.Dispose()

Yeah. My assumption is that it’s actually compiling a C# dll that create that proxy. For some reason, that DLL relies on some sort of dependency that isn’t being met within PSU.

I’ve open an issue for this so I can take a look.

Thank you so much Adam! Really appreciate your help and attention.

I tested this using the straight exe with version 1.5.11, and it works. It’s something to do with either the newer version, or with running in IIS. Hope that helps

So this super weird and I’m not 100% sure why this is happening but I can reproduce this in a regular PS session.

This example comes directly from the New-WebServiceProxy docs.

PS C:\Users\adamr> $URI = "http://www.dneonline.com/calculator.asmx?wsdl"
PS C:\Users\adamr> $calc = New-WebServiceProxy -Uri $URI -Namespace "WSProxy" -Class "Calculator"
New-WebServiceProxy : Could not load file or assembly 'file:///C:\Users\adamr\AppData\Local\Temp\jrrvvlar.dll' or one of its dependencies. The system cannot find the file specified.
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-WebServiceProxy], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.NewWebServiceProxy

If I change this to remove the Namespace and Class, it works.

$calc = New-WebServiceProxy -Uri "http://www.dneonline.com/calculator.asmx?wsdl"

If I change this to a different class name it works.

$calc = New-WebServiceProxy -Uri $URI -Namespace "WSProxy2" -Class "Calculator2" -verbose

Can you try adjusting the Namespace and Class name to see if you have a similar experience?

My guess is that the types loaded in the assembly are failing due to conflicts (or something) but I have yet to get good info out of New-WebServiceProxy to find out why it thinks the DLL can’t be loaded.

With my testing in PSU + IIS I didn’t use Namespace or Class options. In a regular PS session I got the same error as you did with that code, seems it’s related to the URL itself. If I replace that URL with the one I used to test above (http://soapclient.com/xml/SQLDataSoap.WSDL), Class Calculator and Namespace WSProxy work in a local session.

The XML in that calulator link has an invalid targetnamespace of "xmlns:wsdl=“http://schemas.xmlsoap.org/wsdl/” targetNamespace="http://tempuri.org/">"
That might be why it’s acting weird - tempuri.org just redirets to bing.com? EDIT: I don’t think it’s related to that namespace URL - I tested some other soap URLs where that name also didn’t resolve and they seem to be ok with WSProxy and Calculator, huh.

PS C:\scripts> $URI = "http://www.dneonline.com/calculator.asmx?wsdl"

PS C:\scripts> $calc = New-WebServiceProxy -Uri $URI -Namespace "WSProxy" -Class "Calculator"

New-WebServiceProxy : Could not load file or assembly 'file:///C:\Users\User\AppData\Local\Temp\bxdh1ku1\bxdh1ku1.dll' or one of its dependencies. The system cannot find 
the file specified.
At line:1 char:9
+ $calc = New-WebServiceProxy -Uri $URI -Namespace "WSProxy" -Class "Ca ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-WebServiceProxy], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.NewWebServiceProxy
PS C:\scripts> $URI = 'http://soapclient.com/xml/SQLDataSoap.WSDL'

PS C:\scripts> $calc = New-WebServiceProxy -Uri $URI -Namespace "WSProxy" -Class "Calculator"

PS C:\scripts> $calc



SoapVersion                          : Default
AllowAutoRedirect                    : False
CookieContainer                      :
ClientCertificates                   : {}
EnableDecompression                  : False
UserAgent                            : Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.42000)
Proxy                                :
UnsafeAuthenticatedConnectionSharing : False
Credentials                          :
UseDefaultCredentials                : False
ConnectionGroupName                  :
PreAuthenticate                      : False
Url                                  : http://www.soapclient.com/xml/SQLDataSoap.wsdl
RequestEncoding                      :
Timeout                              : 100000
Site                                 :
Container                            :

Ack. I feel silly. I didn’t realize I’d just be able to call your example.

I can reproduce this in IIS. When I run it outside of IIS, it doesn’t happen. I’ll dig around and see what I can find.

1 Like

Seems that guy had a similar issue with the namespace/class and it was related to the data returned by the service (but not that namespace URL). Not sure this is related to the PSU + IIS issue since everything works in PSU by itself but not behind IIS.

I think this might be security related. I dug into that cmdlet (New-WebServiceProxy), it uses the CSharpCodeProvider.

I then found a post about having to provide the app pool identity with write permissions to the temp directory.

I’ve been messing with it a bit but haven’t got it to work quite yet. It would make sense though since this works outside of IIS.

Only thing is, I ran this on my machine-no IIS install or service running-and I’m getting the same error. I did some tracing with procmon and it’s calling csc.exe which is producing the .dll in the $temp (C:\Users$user\appdata\local\temp) directory. It looks like it’s getting created just fine, though it is getting deleted almost right away. I’ve tried catching either the .out, .pdb, or the .dll files via a WMI event but the files are getting deleted faster than the event engine can act on them.

I didn’t see any other obvious errors in the trace, just the exit thread event from Powershell at the end. Still digging around though.

@mackposh You’re saying you got the error running in PSU without IIS / Service account? Or just in regular old powershell console.

Permissions were the first thing I assumed - application pool couldn’t access the temp directories. I set the application pool to run under a local machine admin account. Verified read/write/full control on \windows\temp, \temp, and \users\user\appdata\local\temp - none of which helped :confused:

Just in regular old powershell and IIS is non-existent on my system, and just calling New-WebServiceProxy directly.

I did another test run with assembly binding logging on - got a little more info.

File name: 'file:///C:\Users\User\AppData\Local\Temp\e3weakhk\e3weakhk.dll'
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAss…Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Attempting download of new URL file:///C:/Users/User/AppData/Local/Temp/e3weakhk/e3weakhk.dll.

So I attached Visual Studio’s debugger to the Powershell process which revealed this extra tidbit:
WebServiceProxy_Error

The actual exception is getting thrown around this void Resolve() method: System.Web.Services.Discovery.DiscoveryDocumentReference.Resolve(String contentType, Stream stream)

Error details:

System.InvalidOperationException
  HResult=0x80131509
  Message=Discovery document at the URL http://www.dneonline.com/calculator.asmx?wsdl could not be found.
  Source=System.Web.Services
  StackTrace:
   at System.Web.Services.Discovery.DiscoveryDocumentReference.Resolve(String contentType, Stream stream)

Inner Exception 1:
ArgumentException: The document format is not recognized.

Full output:

'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerShell.ConsoleHost\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.ConsoleHost.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Management.Infrastructure\v4.0_1.0.0.0__31bf3856ad364e35\Microsoft.Management.Infrastructure.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Management\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Management.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.DirectoryServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.DirectoryServices.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'Anonymously Hosted DynamicMethods Assembly'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerShell.Security\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.Security.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\mp\Documents\WindowsPowerShell\Modules\PSReadline\2.2.0\Microsoft.PowerShell.PSReadLine2.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Management\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.Commands.Management.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration.Install\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.Install.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Utility\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.Commands.Utility.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.InteropServices.RuntimeInformation\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.InteropServices.RuntimeInformation.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\mp\Documents\WindowsPowerShell\Modules\PSReadline\2.2.0\net461\Microsoft.PowerShell.PSReadLine.Polyfiller.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Design\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Design.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Security\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Security.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\Microsoft.Management.Infrastructure.Native\v4.0_1.0.0.0__31bf3856ad364e35\Microsoft.Management.Infrastructure.Native.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualC\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualC.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Remoting\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.RegularExpressions\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.RegularExpressions.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibility.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Deployment\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization.Formatters.Soap\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.Serialization.Formatters.Soap.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\System.Data.OracleClient\v4.0_4.0.0.0__b77a5c561934e089\System.Data.OracleClient.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing.Design\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.Design.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.DirectoryServices.Protocols\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.DirectoryServices.Protocols.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceProcess\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.ServiceProcess.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Internals\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Internals.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\SMDiagnostics\v4.0_4.0.0.0__b77a5c561934e089\SMDiagnostics.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Build.Utilities.v4.0\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.Build.Utilities.v4.0.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Build.Framework\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.Build.Framework.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Caching\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.Caching.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Build.Tasks.v4.0\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.Build.Tasks.v4.0.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.JScript\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.JScript.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'. 
'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Dynamic\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Dynamic.dll'. 
Exception thrown: 'System.InvalidOperationException' in System.Web.Services.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.Management.Automation.PipelineStoppedException' in System.Management.Automation.dll
Exception thrown: 'System.Management.Automation.PipelineStoppedException' in System.Management.Automation.dll
Exception thrown: 'System.Management.Automation.CmdletInvocationException' in mscorlib.dll
Exception thrown: 'System.Management.Automation.Interpreter.RethrowException' in System.Management.Automation.dll
Exception thrown: 'System.Management.Automation.CmdletInvocationException' in System.Management.Automation.dll
The thread 0x8688 has exited with code 0 (0x0).
The thread 0x5e24 has exited with code 0 (0x0).
The thread 0x4710 has exited with code 0 (0x0).
The thread 0x49bc has exited with code 0 (0x0).
The thread 0x2e30 has exited with code 0 (0x0).
The thread 0x7f88 has exited with code 0 (0x0).
Exception thrown: 'System.InvalidOperationException' in System.Web.Services.dll
Discovery document at the URL http://www.dneonline.com/calculator.asmx?wsdl could not be found.

'powershell.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Remote Debugger\x64\Runtime\Microsoft.VisualStudio.Debugger.Runtime.Desktop.dll'. 

I think I know what’s happening, although I have no idea why since Microsoft’s documentation doesn’t match the behavior. So, if remove namespace and class parameters and just run:

$calc = New-WebServiceProxy -Uri $uri

it works as previously noted. If I run $calc | gm here is the output. Notice the TypeName:

TypeName: Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy3nline_com_calculator_a
smx_wsdl.Calculator

Now, if I run the following, specifying ‘Calculator2’ as the class, according to Microsoft documentation, I should expect the TypeName to reflect that, but it doesn’t:

$calc = New-WebServiceProxy -Uri $uri -Class 'Calculator2' -Namespace 'WSProxy'
$calc | gm
# According to docs, we should expect to see a TypeName of 'WSProxy.Calculator2' but we don't:
TypeName: WSProxy.Calculator

So, I think what’s happening here is a class name collision. At least in this specific instance. As you can also see from the example above, the Namespace isn’t the problem, it’s the defined Class parameter.