我用.net做的Web service,由java 客户端来调用。
现在如果我发布的方法没有参数,然后返回string,客户端调用没有任何问题,如果我发布的方法,带参数,结果Web service端不能正确地得到这个参数值,好像看起来,java 在soap封装上有些问题?至少WEB端不能够正确地解析。不知道,哪位先生做过相同的事情,提个醒,谢谢了。我的.net framework 是用的1.1 Version.

解决方案 »

  1.   

    import org.apache.axiom.om.OMAbstractFactory;
    import org.apache.axiom.om.OMElement;
    import org.apache.axiom.om.OMException;
    import org.apache.axiom.om.OMFactory;
    import org.apache.axiom.om.OMNamespace;
    import org.apache.axiom.om.OMText;
    import org.apache.axis2.AxisFault;
    import org.apache.axis2.addressing.EndpointReference;
    import org.apache.axis2.client.Options;
    import org.apache.axis2.client.ServiceClient;
    /**
     * invoke acknowledgement webservice
     * 
     * @param endpoint
     *            :web service url
     * @param cmd :
     *            web service method
     * @param msg :
     *            message text
     * @return
     */
    public static String invokeAckSvc(String endpoint, String cmd, String msg)
    throws xxxException
    {
    log.debug("xxx" + endpoint + " webservice."
    + " webservice name is: " + cmd);
    try
    {
    if (null == endpoint)
    {
    throw new xxxException(ErrorCode.NULL);
    }
    String xmlns = "http://tempuri.org/"; OMFactory factory = OMAbstractFactory.getOMFactory(); // access to
    OMNamespace xNs = factory.createOMNamespace(xmlns, "");
    OMElement getQuote = factory.createOMElement(cmd, xNs);
    OMElement strXml = factory.createOMElement("strXml", xNs); <--- 和.net 方法参数对应
    getQuote.addChild(strXml);
    strXml.setText(msg); ServiceClient serviceClient = new ServiceClient(); Options options = new Options();
    EndpointReference targetEPR = new EndpointReference(endpoint);
    options.setTo(targetEPR);
    options.setAction("http://tempuri.org/" + cmd); serviceClient.setOptions(options);
    // step 3 - Blocking invocation
    OMElement result = serviceClient.sendReceive(getQuote); serviceClient.setOptions(options); // step 4 - parse result QName gQR = new QName("http://tempuri.org/", cmd + "Response"); OMElement qResp = (OMElement) result.getChildrenWithName(gQR)
    .next();
    String str = ((OMText) qResp.getFirstOMChild()).getText();
    msg = null;
    return str;
    }
    catch (AxisFault e)
    {
    log.error("xxx" + endpoint
    + " failed. Error reason " + e.getMessage());
    throw new xxxException("xxx");
    }
    catch (OMException e)
    {
    log.error("xxx" + endpoint
    + " failed. Error reason " + e.getMessage());
    throw new xxxException("xxx");
    }
    }供参考
      

  2.   

    我做过没任何问题
    你把参数全定成STRING类型
      

  3.   

    要做通用的话,最好将参数定义成String,对象转换为xml再说