richbon Posted September 28, 2007 Report Share Posted September 28, 2007 I have to access a webservice that requires a user to authenticate with a username and password. How do I do that? Simply using this: invoke-webservice -WSDL https://example.com/_vti_bin/QueryData.asmx?wsdl returns: Invoke-WebService : The remote server returned an error: (401) Unauthorized. I can't be the first person to need to do this, but I've spent the afternoon searching this forum and the web and I can't find anything that seems to apply to my situation. I couldn't find anything in PowerGadgets Creator, either. Can anyone point me in the right direction? Thanks! -Rich Quote Link to comment Share on other sites More sharing options...
marco.shaw Posted September 28, 2007 Report Share Posted September 28, 2007 Although it is not documented, invoke-webservice has a -credential parameter. Try this: PSH>$cred=get-credential <enter your username and password> PSH>invoke-webservice -credential $cred -WSDL https://example.com/_vti_bin/QueryData.asmx?wsdl Marco Quote Link to comment Share on other sites More sharing options...
richbon Posted October 1, 2007 Author Report Share Posted October 1, 2007 Thanks for the reply, but it doesn't seem to be working for me for some reason. I can create the credential fine, but then it still gives me this error: Invoke-WebService : The remote server returned an error: (401) Unauthorized.At line:1 char:18+ invoke-webservice <<<< -credential $cred -WSDL https://example.com/_vti_bin/QueryData.asmx?wsdl Now, I know definitely the account I'm using works, because I can open the link in IE and get the whole wsdl definitions and operations list. Any other thoughts? This would be perfect if we could get it working. -Rich Quote Link to comment Share on other sites More sharing options...
marco.shaw Posted October 1, 2007 Report Share Posted October 1, 2007 Can I try it somehow? I don't know of a 'public' webservice requiring authentication that I can test. Do you have any strange characters in your username or password? Maybe there's some kind of problem with the string passed... Otherwise, I might be able to whip a test up if I can borrow some C# code online to create my own webservice... Quote Link to comment Share on other sites More sharing options...
JuanC Posted October 1, 2007 Report Share Posted October 1, 2007 What kind of authentication are you using in your web service Windows Auth? Basic? JuanC Quote Link to comment Share on other sites More sharing options...
richbon Posted October 1, 2007 Author Report Share Posted October 1, 2007 I asked our developer, and he said it's using Basic authentication. Of note: in IE, I can use DOMAIN\username or just username and both versions work. Neither version works with invoke-webservice. There are no strange characters in the username or password - just letters (upper and lower case) and numbers. Also, I don't know if it matters, but notice that the webservice is using https. -Rich Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.