Closed lihlcnkr closed 7 years ago
I have found that winrm4j does not work with WinRM v2.0. I think at a minimum it needs WinRM v3.0. You might want to check the version of WinRM (using command: winrm id) on your Windows 2008 r2 system.
@awdamle , thx very much. so is winrm4j have any plan to support winrm 2.0?
@lihlcnkr I don't have any idea about that. I am not a contributor for winrm4j, but I too would like to see support for WinRM 2.0 in winrm4j.
@lihlcnkr, @awdamle There are no immediate plans to support 2.0. What features from 2.0 would be useful to you? What limitations do you face in the current implementation?
@lihlcnkr Can you attach a network capture of the traffic with windows 2008?
@neykov support 2.0 is very useful for me. because winrm 2.0 is default version for windows 7 and windows 2008 R2. (https://technet.microsoft.com/en-us/library/ff520073(v=ws.10).aspx) there are so many company is still using windows 2008 R2, because they are conservative, hate to taking risk for upgrade OS.
so I using ruby winrm library instead of winrm4j, despite I'm very looking foward for winrm4j because there are no other good winrm library for java.
@neykov how to capture network of the traffic? if you need, I can attach winrm4j debug info for windows 2008R2.
@lihlcnkr I use Wireshark
Issue is Response from Power shell 2.0 does not contain Shell part.
Response from 2.0
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:x="http://schemas.xmlsoap.org/ws/2004/09/transfer" xmlns:w="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" xmlns:rsp="http://schemas.microsoft.com/wbem/wsman/1/windows/shell" xmlns:p="http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd" xml:lang="en-US">
<s:Header>
<a:Action>http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse</a:Action>
<a:MessageID>uuid:154DD72B-1363-4D14-9FDD-C75A5CA08A7F</a:MessageID>
<a:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:To>
<a:RelatesTo>urn:uuid:94cdeeb9-8d8e-41da-86e0-b8304510f9dc</a:RelatesTo>
</s:Header>
<s:Body>
<x:ResourceCreated>
<a:Address>https://blb44cehhttps1.cehdev.com:5986/wsman</a:Address>
<a:ReferenceParameters>
<w:ResourceURI>http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd</w:ResourceURI>
<w:SelectorSet>
<w:Selector Name="ShellId">CF90921E-B222-4223-8F80-2B58C40FC10E</w:Selector>
</w:SelectorSet>
</a:ReferenceParameters>
</x:ResourceCreated>
</s:Body>
</s:Envelope>
Response from 4.0
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:x="http://schemas.xmlsoap.org/ws/2004/09/transfer" xmlns:w="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" xmlns:rsp="http://schemas.microsoft.com/wbem/wsman/1/windows/shell" xmlns:p="http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd" xml:lang="en-US">
<s:Header>
<a:Action>http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse</a:Action>
<a:MessageID>uuid:AB9A08D5-08E8-40F7-9BAC-848A23376AA1</a:MessageID>
<a:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:To>
<a:RelatesTo>urn:uuid:a288c91f-0cdd-4070-a750-e8cf7a6b48e9</a:RelatesTo>
</s:Header>
<s:Body>
<x:ResourceCreated>
<a:Address>https://x.x.x.x:5986/wsman</a:Address>
<a:ReferenceParameters>
<w:ResourceURI>http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd</w:ResourceURI>
<w:SelectorSet>
<w:Selector Name="ShellId">713E06DC-6876-4487-B930-2880C8E45A59</w:Selector>
</w:SelectorSet>
</a:ReferenceParameters>
</x:ResourceCreated>
<rsp:Shell xmlns:rsp="http://schemas.microsoft.com/wbem/wsman/1/windows/shell">
<rsp:ShellId>713E06DC-6876-4487-B930-2880C8E45A59</rsp:ShellId>
<rsp:ResourceUri>http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd</rsp:ResourceUri>
<rsp:Owner>administrator</rsp:Owner>
<rsp:ClientIP>x.x.x.x</rsp:ClientIP>
<rsp:IdleTimeOut>PT7200.000S</rsp:IdleTimeOut>
<rsp:InputStreams>stdin</rsp:InputStreams>
<rsp:OutputStreams>stdout stderr</rsp:OutputStreams>
<rsp:ShellRunTime>P0DT0H0M0S</rsp:ShellRunTime>
<rsp:ShellInactivity>P0DT0H0M0S</rsp:ShellInactivity>
</rsp:Shell>
</s:Body>
</s:Envelope>
To make it work with 2.0 please make below code changes 1.In WinRm.java for the method Create change the webparm as below.
@WebParam(name = "Shell", targetNamespace = "http://schemas.microsoft.com/wbem/wsman/1/windows/shell")
io.cloudsoft.winrm4j.service.shell.Shell shell,
//final Holder<Shell> holder = new Holder<>(shell);
ResourceCreated resourceCreated = winrmCallRetryConnFailure(new CallableFunction<ResourceCreated>() {
@Override
public ResourceCreated call() {
//TODO use different instances of service http://cxf.apache.org/docs/developing-a-consumer.html#DevelopingaConsumer-SettingConnectionPropertieswithContexts
setActionToContext((BindingProvider) winrm, "http://schemas.xmlsoap.org/ws/2004/09/transfer/Create");
return winrm.create(shell, RESOURCE_URI, MAX_ENVELOPER_SIZE, operationTimeout, locale, optSetCreate);
}
});
Hi @Arulanand, thanks for the extensive troubleshooting. That's really helpful. I've reached the same conclusion in the last couple of days and posted a question hoping there's a nice solution which accommodates both versions of the service (spoiler - don't believe there's one).
The code used to behave just as you suggested above, but then it doesn't work with the newer versions.
That's all related to the JAX-WS limitations of handling multiple elements in the response body. At this point I'm thinking it's better to throw it away and create the XML request and response manually - too much time spent in making it work with this particular service.
See https://github.com/cloudsoft/winrm4j/pull/45 for a fix.
Fix included in the just released winrm4j 0.5.0
HI, when I use winrm4j to run executeCommand on windows 2008 r2, It throw SOAPFaultException.
javax.xml.ws.soap.SOAPFaultException: Index: 1, Size: 1
and I using winrm ruby code, it works well.when using same winrm4j code, on windows 2012 R2, executeCommand it works well too.
looks like winrm4j is not works well on windows 2008 r2 (korean language pack) or other language pack.