从 Powershell 调用具有用户名过度传输安全性的 WCF 服务终结点



我正在运行使用 UserNameOverTransport 身份验证的 WCF 服务。这是web.config中的配置:

<service name="ReportService" behaviorConfiguration="ReportServiceBehaviors">
    <endpoint address="UsernameMixed" binding="customBinding" bindingConfiguration="BasicHttpBinding_ReportService_UsernameMixed" contract="IReportService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>

具有以下绑定和行为:

<customBinding>
    <binding name="BasicHttpBinding_ReportService_UsernameMixed">
        <security authenticationMode="UserNameOverTransport" allowInsecureTransport="false" />
        <textMessageEncoding messageVersion="Soap11" writeEncoding="utf-8" />
        <httpTransport transferMode="Buffered" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
    </binding>
</customBinding>
<serviceBehaviors>
    <behavior name="ReportServiceBehaviors">
        <serviceDebug includeExceptionDetailInFaults="true" />
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
        <!-- Enable WIF-Configuration -->
        <serviceCredentials useIdentityConfiguration="true" />
        <serviceAuthorization principalPermissionMode="Always" />
    </behavior>
</serviceBehaviors>

我正在尝试在Powershell脚本中调用该服务:

$uri = 'https://myserver/ReportService?wsdl'
$password = ConvertTo-SecureString "s3cr3t" -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential ("foobar", $password)
$proxy = New-WebServiceProxy -Uri $uri -Credential $credentials -Namespace PsReportService
$model = New-Object PsReportService.UserReportModel
$result = $proxy.GetUserReport($model)

我收到以下错误消息:

Ausnahme beim Aufrufen von "GetUserReport" mit 1 Argument(en):  "An error occurred when verifying security for the message."
In Zeile:6 Zeichen:1
+ $result = $proxy.GetUserReport($model)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SoapHeaderException

更新修复了一些错别字(谢谢@rAJ(

试试这个:

$uri = "https://myserver/ReportService?wsdl"
$username = "foobar"
$password = "s3cr3t"
$SecurePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential `
     -argumentlist $username, $SecurePassword
$proxy = New-WebServiceProxy -Uri $uri -Credential $cred -Namespace PsReportService

相关内容

  • 没有找到相关文章

最新更新