我正在运行使用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)
答案 0 :(得分:0)
尝试一下:
$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