I have a WCF service that uses wsHttpBinding with message security and clientcredentialtype as windows, and the service has a simple method
[OperationContract]
string SayHello();
public string SayHello()
{
return "HELLO";
}
<wsHttpBinding>
<binding name="WSHttpBinding">
<security mode="Message">
<message clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
I am trying to execute the below on powershell(version >= 2) and I get the below error
$wshttpbinding= New-WebServiceProxy -uri http://localhost:52871/Service.svc -Credential DOMAIN\gop
PS> $wshttpbinding.SayHello.Invoke()
Exception calling "SayHello" with "0" argument(s): "The operation has timed out"
At line:1 char:1
+ $wshttpbinding.SayHello.Invoke()
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
However when i changed the binding to use basicHttpBinding, it works fine
<basicHttpBinding>
<binding name="basicconfig"
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
$basichttpbinding= New-WebServiceProxy -uri http://localhost:52871/Service.svc -Credential DOMAIN\gop
PS> $basichttpbinding.SayHello.Invoke()
HELLO
Is there anything differently that i need to do in my script when using wsHttpBinding ?
Thanks in advance.
Final Approach I was using wsHttpBinding only for WCF transaction support. However I quickly realised that the service method call that was required to be called by the powershell script has nothing to do with transactions. Hence I exposed another BasicHttpBinding endpoint with Windows Authentication and it worked with the below script. See snippet below
Try
{
$cred = new-object -typename System.Management.Automation.PSCredential ` -argumentlist $username, $password -ErrorAction Stop
}
Catch {
LogWrite "Could not create PS Credential"
$credErrorMessage = $_.Exception.Message
LogWrite $credErrorMessage
Break
}
Try{
$service=New-WebServiceProxy –Uri $url -Credential $cred -ErrorAction Stop
} Catch {
LogWrite "Could not create WebServiceProxy with $url"
$proxyErrorMessage = $_.Exception.Message
LogWrite $proxyErrorMessage
Break
}
# Create Request Object
$namespace = $service.getType().namespace
$req = New-Object ($namespace + ".UpdateJobRequest")
LogWrite "Calling service..."
$response = $service.UpdateJob($req)
$wsHttpBinding = new-object System.ServiceModel.WSHttpBinding
– TomcatService.scv
and look at the request. Is your powershell instance logged in as you? Is it running as admin? – Tomcat