我已经从 wsdl 文件生成了一些 Java 代码,并且请求本身似乎正在运行,但我无法发送我的凭据。我已经用一个名为“SoapUI”的工具测试了 Webservice,一切似乎都在运行。这是(工作)xml 的示例:<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:beac="url"> <soapenv:Header> <nsAuthn:authnHeader xmlns:nsAuthn="url/auth"> <nsAuthn:id>id</nsAuthn:id> <nsAuthn:password>password</nsAuthn:password> </nsAuthn:authnHeader> </soapenv:Header> <soapenv:Body> <beac:getData> <saisonid>int</saisonid> </beac:getData> </soapenv:Body></soapenv:Envelope>这是我的尝试:public RankDtoResponse getData(int saisonid) throws java.rmi.RemoteException, SOAPException { if (super.cachedEndpoint == null) { throw new org.apache.axis.NoEndPointException(); } SOAPHeaderElement authentication = new SOAPHeaderElement("url","auth"); SOAPHeaderElement user = new SOAPHeaderElement("url","id", "id"); SOAPHeaderElement password = new SOAPHeaderElement("url","password", "password"); try { authentication.addChild(user); authentication.addChild(password); } catch (SOAPException e) { // TODO Auto-generated catch block e.printStackTrace(); } org.apache.axis.client.Call _call = createCall(); _call.setOperation(_operations[3]); _call.setUseSOAPAction(true); _call.setSOAPActionURI(""); _call.setEncodingStyle(null); _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE); _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE); _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS); _call.setOperationName(new javax.xml.namespace.QName("url", "getData")); setHeader(authentication); setRequestHeaders(_call); setAttachments(_call); try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] {new java.lang.Integer(saisonid)}); 大多数代码是由 wsdl2java 从 wsdl 文件自动生成的。你需要更多信息吗?我错过了什么吗?提前致谢
2 回答
阿晨1998
TA贡献2037条经验 获得超6个赞
您的代码对我来说看起来不错,所以不确定实际问题在哪里。但是我没有修改存根类,而是在调用服务方法时完成了它。您的代码应该如下所示,您可以删除对生成的存根类的代码修改,它应该可以工作。
OMNamespace hdrNs =
OMAbstractFactory.getOMFactory().createOMNamespace("url/auth", "nsAuthn");
SOAPHeaderBlock header = OMAbstractFactory.getSOAP12Factory().createSOAPHeaderBlock("authnHeader", hdrNs);
header.addChild(AXIOMUtil.stringToOM("<id>$id</id>"));
header.addChild(AXIOMUtil.stringToOM("<password>$id</password>"));
stub._getServiceClient().addHeader(header);
希望它会有所帮助!
添加回答
举报
0/150
提交
取消