【问题标题】:How to define timeout for webservice client in websphere如何在 websphere 中为 webservice 客户端定义超时
【发布时间】:2013-02-27 10:16:39
【问题描述】:

我们的应用程序托管在 websphere 中,我的 web 服务客户端 (jax-ws) 正在对远程服务器进行 web 服务调用。我需要为此 Web 服务调用定义超时。我尝试了不同的方法来设置超时,但没有运气。这是我尝试过的:

    Map<String, Object> requestContext = ((BindingProvider) binding).getRequestContext();
    requestContext.put("com.ibm.websphere.webservices.jaxws.asynctimeout", 15000); 

    Map<String, Object> requestContext = ((BindingProvider) binding).getRequestContext();
    requestContext.put(BindingProviderProperties.REQUEST_TIMEOUT, 15000);
    requestContext.put(BindingProviderProperties.CONNECT_TIMEOUT, 15000); 

它们都不起作用

任何人都可以给出提示,如何在 websphere 中为 webservice 客户端设置超时?

谢谢

【问题讨论】:

    标签: web-services timeout websphere


    【解决方案1】:

    因为 WAS 中的 Jax-WS 依赖于 Axis 2,我相信您可以使用标准的 Axis 2 方法来做到这一点,请尝试(来自 axis 2 文档):

    超时配置

    传输层存在两个超时实例,Socket超时和连接超时。这些可以在部署或运行​​时进行配置。如果在部署时配置,用户必须在axis2.xml中添加以下行。

    对于 Socket 超时:

    <parameter name="SO_TIMEOUT">some_integer_value</parameter>
    For Connection timeout:
    
     <parameter name="CONNECTION_TIMEOUT">some_integer_value</parameter>
    

    对于运行时配置,可以在客户端存根中进行如下设置: ...

    Options options = new Options();
    options.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(timeOutInMilliSeconds));
    options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(timeOutInMilliSeconds));
    
    // or
    options.setTimeOutInMilliSeconds(timeOutInMilliSeconds);
    ...
    

    如果您想了解更多信息,请查看:http://axis.apache.org/axis2/java/core/docs/http-transport.html

    还有:

    http://wso2.org/library/209

    http://singztechmusings.wordpress.com/2011/05/07/how-to-configure-timeout-duration-at-client-side-for-axis2-web-services/

    如果您使用 ServiceClient,请检查此线程:Axis2 ServiceClient options ignore timeout

    如果它有效,请告诉我;)

    【讨论】:

    • 我们使用ServiceClient方式而不是stub方式来调用远程服务。我不知道是否有办法从 PortType 获取存根。
    • 我已更新我的答案以指向另一个 StackOverflow 线程中的解决方案。希望对您有所帮助。
    • 感谢您的回复,我以为我有 serviceClient,但是当我回到生成的 websphere 代码时,我所拥有的是:扩展 javax.xml.ws.Service 和 porttype 的类,我不能弄清楚如何在两者之一上设置选项。
    【解决方案2】:

    您应该设置以下链接中提到的 JVM 属性 -

    https://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.nd.doc/ae/rwbs_jaxwstimeouts.html

    bindingProvider.getRequestContext().put(com.ibm.wsspi.webservices.Constants.CONNECTION_TIMEOUT_PROPERTY, timeout);
    bindingProvider.getRequestContext().put(com.ibm.wsspi.webservices.Constants.RESPONSE_TIMEOUT_PROPERTY, timeout);
    

    将超时时间设置为字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-18
      • 2017-05-19
      • 1970-01-01
      • 2011-07-11
      • 1970-01-01
      相关资源
      最近更新 更多