2013-12-13 59 views
2

是否有某種方法可以使用PowerShell連接到具有消息級用戶憑證的Web服務。PowerShell WCF消息級用戶憑證

我有一個與我連接指定的憑據如下C#程序的偉大工程,一個測試Web服務:

DEVService.ServerLinkClient webService = new DEVService.ServerLinkClient("ServerLinkEndPoint"); 
webService.ClientCredentials.UserName.UserName = "*****"; 
webService.ClientCredentials.UserName.Password = ""*****"; 

Web服務的配置如下:

<bindings> 
    <basicHttpBinding> 
    <binding name="ServerLinkBinding" maxBufferSize="2097152" maxReceivedMessageSize="2097152" 
      maxBufferPoolSize="2097152" sendTimeout="00:02:00" receiveTimeout="00:02:00"> 
     <security mode="TransportWithMessageCredential"> 
     <message clientCredentialType="UserName" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

<services> 
    <service name="APOServiceLibrary.ServerLink" 
      behaviorConfiguration="SecureBehaviourServerLink"> 
    <endpoint name="ServerLinkEndPoint" 
       address="" 
       binding="basicHttpBinding" 
       bindingConfiguration="ServerLinkBinding" 
       contract="APOServiceLibrary.IServerLink"> 
    </endpoint> 
    <endpoint address="mexServerLink" 
       binding="mexHttpsBinding" 
       contract="IMetadataExchange"> 
    </endpoint> 
    </service> 
</services> 


<behaviors> 
    <serviceBehaviors>  
    <behavior name="SecureBehaviourServerLink"> 
     <serviceMetadata httpsGetEnabled="True"/> 
     <serviceDebug includeExceptionDetailInFaults="False"/> 
     <serviceCredentials> 
     <userNameAuthentication userNamePasswordValidationMode="Custom" 
customUserNamePasswordValidatorType="APOServiceLibrary.ConnectionSecurityServerLink, APOServiceLibrary"/> 
     </serviceCredentials> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

我已經使用PowerShell連接到一個簡單的Web服務,但該服務已設置爲使用Windows身份驗證。在這種情況下,傳輸層只是基本安全的,並且消息正在等待某個用戶名和密碼。

這是我想要使用來從Web服務的數據集的腳本:

#setup the credentials to connect 
$securePasswd = ConvertTo-SecureString "*******" -AsPlainText -Force 
$tempCredentials = New-Object System.Management.Automation.PSCredential (""*******" ", $securePasswd) 

# Connect to the web services 
$web_serv = New-WebServiceProxy -uri https://127.0.0.1/ServerLink.svc -Credential $tempCredentials 

# get some data 
$test_data = New-Object System.Data.DataSet 
$test_data = $web_serv.getDataSet() 

然而,當我嘗試使用憑據連接並嘗試運行一個命令,我得到以下錯誤:

Exception calling "getDataSet" with "0" argument(s): "An error occurred when verifying security for the message." 

任何幫助將是真棒!
甚至要知道是否有可能將某種消息級別的用戶名和密碼放入PowerShell連接將會很好!

回答

0

我發現這一點: http://social.technet.microsoft.com/Forums/windowsserver/en-US/54d89b12-8623-47d1-8873-b4ba7927a4a5/powershell2-newwebserviceproxy-soap-security-header?forum=winserverpowershell

基本上表明PowerShell的新WebServiceProxy命令行不夠詳細應對這種複雜性。

爲此,我已經在我的問題,通過更改Web服務只使用tranport安全如下工作:

<binding name="ServerLinkBinding" maxBufferSize="2097152" maxReceivedMessageSize="2097152" 
     maxBufferPoolSize="2097152" sendTimeout="00:02:00" receiveTimeout="00:02:00"> 
    <security mode="Transport" /> 
</binding> 

,並要求用戶名和密碼提供給每個方法(這在我的情況下,因爲方法數量有限而工作)。