Reputation: 195
Is there some way to connect to a web service that has message level user credentials using powershell.
I have a tested web service that works great with a C# program that I connect specifying credentials as follows:
DEVService.ServerLinkClient webService = new DEVService.ServerLinkClient("ServerLinkEndPoint");
webService.ClientCredentials.UserName.UserName = "*****";
webService.ClientCredentials.UserName.Password = ""*****";
The configuration of the web service is as follows:
<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>
I have connect to a simple web service in the past with powershell, but that service was setup to use windows authentication. In this case, the transportation layer is just basic secured, and the message is expecting a certain username and password.
This is the scripting I'm trying to use to fetch a data set from the web service:
#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()
However, when I try to connect using credentials and try to run a command I get the following error:
Exception calling "getDataSet" with "0" argument(s): "An error occurred when verifying security for the message."
Any help would be awesome!
Or even to know if it's possible to put some sort of message level username and password into the powershell connection would be good to!
Upvotes: 2
Views: 1359
Reputation: 195
Basically suggesting that the powershell New-WebServiceProxy commandlet is not detailed enough to deal with this level of complexity.
To that end, I have worked around my problem by changing the web service to only use tranport security as follows:
<binding name="ServerLinkBinding" maxBufferSize="2097152" maxReceivedMessageSize="2097152"
maxBufferPoolSize="2097152" sendTimeout="00:02:00" receiveTimeout="00:02:00">
<security mode="Transport" />
</binding>
And requiring a username and password be provided to each method (which in my case works because of the limited number of methods).
Upvotes: 0