首页 > 代码库 > java 调用webservice接口(asmx)
java 调用webservice接口(asmx)
进入.asmx的链接,找到方法名、命名空间等
import javax.xml.namespace.QName; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.message.SOAPHeaderElement; /** * Created by liwj on 2017/6/15. */ public class AsmxTest {private static String urlhsb=""; private static String namespaceURI=""; public static void main(String[] args){ String xsXml=""; Service service=new Service(); try { Call call=(Call)service.createCall(); call.setTargetEndpointAddress(urlhsb); //设置要调用哪个方法 call.setOperationName(new QName(namespaceURI,"GetCbzm")); call.addParameter(new QName(namespaceURI,"xml"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING); call.setUseSOAPAction(true); call.setSOAPActionURI(namespaceURI); //设置soapHeader SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement(namespaceURI, "ValidationSoapHeader"); soapHeaderElement.setNamespaceURI(namespaceURI); try { soapHeaderElement.addChildElement("UserName").setValue(""); soapHeaderElement.addChildElement("PassWord").setValue(""); call.addHeader(soapHeaderElement); }catch (Exception e){ } String res=String.valueOf(call.invoke(new Object[]{xsXml})); System.out.println(res); }catch (Exception e){ System.out.println(e.getMessage()); } } }
java 调用webservice接口(asmx)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。