从xfire客户端调用axis2 Web服务:未找到操作的端点引用(EPR)

时间:2022-03-21 16:50:29

I need to call axis2 web service with ws-security (username token) from xfire client over https. I could do the exercise via xfire dynamic client, but no luck with wsdl base client (i.e. generate java stub from wsdl). Could anybody point me out what could be wrong (stub, ws-security something else)?

我需要通过https从xfire客户端使用ws-security(用户名令牌)调用axis2 Web服务。我可以通过xfire动态客户端进行练习,但是没有运气wsdl基本客户端(即从wsdl生成java存根)。任何人都可以指出我可能出错的地方(存根,ws-安全别的东西)?

Exception:

Exception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: The endpoint reference (EPR) for the Operation not found is https://localhost/services/DataServiceSample2 and the WSA Action = org.codehaus.xfire.fault.XFireFault: The endpoint reference (EPR) for the Operation not found is https://localhost/services/DataServiceSample2 and the WSA Action =

线程“main”中的异常org.codehaus.xfire.XFireRuntimeException:无法调用服务。嵌套异常是org.codehaus.xfire.fault.XFireFault:未找到Operation的端点引用(EPR)是https:// localhost / services / DataServiceSample2和WSA Action = org.codehaus.xfire.fault.XFireFault:未找到Operation的端点引用(EPR)是https:// localhost / services / DataServiceSample2,WSA Action =

Code:

public static void main(String[] args) throws MalformedURLException {
    ProtocolSocketFactory easy = new EasySSLProtocolSocketFactory();
    Protocol protocol = new Protocol("https", easy, 9443);
    Protocol.registerProtocol("https", protocol);

    ObjectServiceFactory serviceFactory = new ObjectServiceFactory();
    serviceFactory.setStyle("message");
    Service serviceModel = serviceFactory.create(DataServiceSample2PortType.class);
    XFireProxyFactory factory = new XFireProxyFactory();
    DataServiceSample2PortType service = (DataServiceSample2PortType) factory.create(serviceModel, "https://localhost:9443/services/DataServiceSample2");
    Client client = Client.getInstance(service);
client.addOutHandler(new DOMOutHandler());

    Properties properties = new Properties();
    properties.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    properties.setProperty(WSHandlerConstants.USER, "admin");
    properties.setProperty(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    properties.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, PasswordHandler.class.getName());
    client.addOutHandler(new WSS4JOutHandler(properties));

    sab.TopCustomerResponse topCustomersInCalifornia = service.topCustomersInCalifornia(null);
}

2 个解决方案

#1


0  

Please try replacing the localhost with ip address of the machine where your service is running. Instead of

请尝试使用运行服务的计算机的IP地址替换localhost。代替

factory.create(serviceModel,"https://localhost:9443/services/DataServiceSample2");

You can try specifying the ip address like this

您可以尝试像这样指定IP地址

factory.create(serviceModel,"https://192.168.2.18:9443/services/DataServiceSample2");

Please note that it is considered bad practice to ship code with ambiguous parameters. So after testing it you will need to replace hard coded ip address with some variable which can be easily configured.

请注意,使用含糊不清的参数发送代码被视为不良做法。因此,在测试之后,您将需要将硬编码的IP地址替换为可以轻松配置的变量。

#2


0  

I'm missing "SOAPAction" parameter in HTTP header. You could set it directly as

我在HTTP标头中缺少“SOAPAction”参数。您可以直接将其设置为

HttpsURLConnection conn;
...
conn.setRequestProperty("SOAPAction", "urn:executeXml");

AFAIK in XFire client it could be archived in such way:

XFire客户端中的AFAIK可以通过以下方式存档:

    Map m = new HashMap();
    m.put("SOAPAction", "urn:executeXml");
    client.setProperty(CommonsHttpMessageSender.HTTP_HEADERS, m);

#1


0  

Please try replacing the localhost with ip address of the machine where your service is running. Instead of

请尝试使用运行服务的计算机的IP地址替换localhost。代替

factory.create(serviceModel,"https://localhost:9443/services/DataServiceSample2");

You can try specifying the ip address like this

您可以尝试像这样指定IP地址

factory.create(serviceModel,"https://192.168.2.18:9443/services/DataServiceSample2");

Please note that it is considered bad practice to ship code with ambiguous parameters. So after testing it you will need to replace hard coded ip address with some variable which can be easily configured.

请注意,使用含糊不清的参数发送代码被视为不良做法。因此,在测试之后,您将需要将硬编码的IP地址替换为可以轻松配置的变量。

#2


0  

I'm missing "SOAPAction" parameter in HTTP header. You could set it directly as

我在HTTP标头中缺少“SOAPAction”参数。您可以直接将其设置为

HttpsURLConnection conn;
...
conn.setRequestProperty("SOAPAction", "urn:executeXml");

AFAIK in XFire client it could be archived in such way:

XFire客户端中的AFAIK可以通过以下方式存档:

    Map m = new HashMap();
    m.put("SOAPAction", "urn:executeXml");
    client.setProperty(CommonsHttpMessageSender.HTTP_HEADERS, m);