【问题标题】:Call WCF service endpoint with UserNameOverTransport security from Powershell从 Powershell 调用具有 UserNameOverTransport 安全性的 WCF 服务端点
【发布时间】:2019-09-14 19:16:46
【问题描述】:

我正在运行使用 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)

【问题讨论】:

    标签: powershell wcf wif


    【解决方案1】:

    试试这个:

    $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
    

    【讨论】:

    • 这不是和我的剧本一样吗?但是,它不起作用。还是一样的例外。
    • 您的凭据和 Uri 分配错误。您的问题仍然不正确。正确 -Uri $credentials -Credential $uri => -Uri $uri -Credential $credentials 应该可以解决您的凭证提示问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-03
    • 2015-11-16
    • 2010-09-18
    • 1970-01-01
    • 2012-02-13
    • 1970-01-01
    相关资源
    最近更新 更多