我尝试连接(没有成功)以下WS使用Java:与TERYT集成 - 波兰政府网络服务
- 服务地址 - https://uslugaterytws1test.stat.gov.pl/terytws1.svc
- WSDL地址 - https://uslugaterytws1test.stat.gov.pl/wsdl/terytws1.wsdl
- 用户 - TestPubliczny
- 密码 - 1234ABCD
我想我们e soapui没有成功。试过基本和NTLM身份验证,而我总是得到以下错误:下面的例子此Web服务节目
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
</s:Header>
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">a:InvalidSecurity</faultcode>
<faultstring xml:lang="en-US">An error occurred when verifying security for the message.</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>
的官方说明使用C#进行连接。我没有测试过这个,但我认为它能正常工作。
try {
var proxy = new ChannelFactory<ServiceReferenceWCF.ITerytWs1>("custom");
proxy.Credentials.UserName.UserName = login;
proxy.Credentials.UserName.Password = haslo;
var result = proxy.CreateChannel();
var test = result.CzyZalogowany(); // should return true if connected correctly
} catch (Exception ex) { }
及以下设置:
<client>
<endpoint address="https://uslugaterytws1.stat.gov.pl/TerytWs1.svc" binding="customBinding" bindingConfiguration="custom" contract="ServiceReference1.ITerytWs1" name="custom" />
</client>
<bindings>
<customBinding>
<binding name="custom">
<security defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport" requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
<localClientSettings detectReplays="false" />
<localServiceSettings detectReplays="false" />
</security>
<textMessageEncoding messageVersion="Soap11WSAddressing10" />
<httpsTransport maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" />
</binding>
</customBinding>
</bindings>
所以,我试图用Java以下方式连接:
public static void main(String[] args) {
try {
final String wsdlResourcePath = "wsdl/jaxb/teryt/terytws1.wsdl";
final String url = "https://uslugaterytws1test.stat.gov.pl/TerytWs1.svc";
ITerytWs1 teryt = createSoapEndpoint((wsdlLocation) -> new TerytWs1(wsdlLocation).getCustom(), wsdlResourcePath, url);
System.out.println(teryt.czyZalogowany());
} catch (Exception e) { }
}
private static <SOAP> SOAP createSoapEndpoint(SoapCreator<SOAP> soapCreator, String wsdlResourcePath, String url) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL wsdlLocation = cl.getResource(wsdlResourcePath);
SOAP soap = soapCreator.create(wsdlLocation);
BindingProvider provider = (BindingProvider) soap;
Map<String, Object> context = provider.getRequestContext();
context.put(BindingProvider.USERNAME_PROPERTY, "TestPubliczny");
context.put(BindingProvider.PASSWORD_PROPERTY, "1234abcd");
context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
return soap;
}
不幸的是,代码调用过程中 “teryt.czyZalogowany()” 冻结。不给予超时 - 任何事情,只是永远处理这条线,或者被阻止。
我的Java代码会产生以下警告消息:
WARNING: WSP0075: Policy assertion "{ http://schemas.xmlsoap.org/ws/2005/07/securitypolicy }SignedSupportingTokens" was evaluated as "UNKNOWN". lip 27, 2017 11:58:35 AM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector] selectAlternatives WARNING: WSP0075: Policy assertion "{ http://schemas.xmlsoap.org/ws/2005/07/securitypolicy }TransportBinding" was evaluated as "UNKNOWN". lip 27, 2017 11:58:35 AM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector] selectAlternatives WARNING: WSP0075: Policy assertion "{ http://schemas.xmlsoap.org/ws/2005/07/securitypolicy }Trust10" was evaluated as "UNKNOWN". lip 27, 2017 11:58:35 AM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector] selectAlternatives WARNING: WSP0075: Policy assertion "{ http://schemas.xmlsoap.org/ws/2005/07/securitypolicy }Wss11" was evaluated as "UNKNOWN". lip 27, 2017 11:58:35 AM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector] selectAlternatives WARNING: WSP0075: Policy assertion "{ http://www.w3.org/2006/05/addressing/wsdl }UsingAddressing" was evaluated as "UNKNOWN". lip 27, 2017 11:58:35 AM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector] selectAlternatives WARNING: WSP0019: Suboptimal policy alternative selected on the client side with fitness "UNKNOWN".
也许有人知道更多关于这类问题,或将能够用他自己的配置马上连接到这个WS - 此刻我不没有一个线索可能是什么问题,我看到在我面前有一个“浪费时间”的观点......所以请帮助。
谢谢bartosz。现在 - 在打开地址的情况下 - Java响应与soapui一致:“验证消息的安全性时发生错误。”看起来有更多的配置丢失。您是否能够连接并接收来自此Web服务的成功响应? – msi