我正在尝试执行以下操作:
$basicHttpBinding = New-Object System.ServiceModel.BasicHttpBinding([System.ServiceModel.BasicHttpSecurityMode]::TransportCredentialOnly);
$basicHttpBinding.Security.Transport.ClientCredentialType = [System.ServiceModel.HttpClientCredentialType]::Windows;
$basicHttpBinding.MaxBufferSize = 65536000;
$basicHttpBinding.MaxReceivedMessageSize = 65536000;
$basicHttpBinding.MaxBufferPoolSize = 524288;
$basicHttpBinding.CloseTimeout = "01:01:00";
$basicHttpBinding.OpenTimeout = "01:01:00";
$basicHttpBinding.ReceiveTimeout = "01:01:00";
$basicHttpBinding.SendTimeout = "01:01:00";
$mexClient = New-Object System.ServiceModel.Description.MetadataExchangeClient($basicHttpBinding);
$mexClient.MaximumResolvedReferences = [System.Int32]::MaxValue
$metadataSet = $mexClient.GetMetadata([Uri]$WsdlUrl, $mode)
无论出于何种原因,MexClient 似乎都没有传递凭据。我这样说是因为当我在 IE 中以与脚本相同的用户身份浏览 $WsdlUrl 时,我可以看到 wsdl 很好。当我运行上面的代码时,我得到一个异常:
使用“2”参数调用“GetMetadata”的异常:“元数据包含无法解析的引用:'http_://myServer:myPort/myVirtualDirectory/myWcfService.svc?wsdl'。” ---> System.InvalidOperationException:元数据包含无法解析的引用:'http_://myServer:myPort/myVirtualDirectory/myWcfService.svc?wsdl'。---> System.Net.WebException:远程服务器返回错误:(401)未经授权。
编辑 01
MetadataExchangeClient 似乎也没有通过 http 传输请求。当我使用提琴手时,没有发送“请求”,只有失败的 HTTP 响应。如何让 MexClient 通过 http 发送和接收?