问题描述
publicstaticStringinterfaceInvokeToString(Stringdestination,StringoperateFun,Mapparameter)throwsSOAPException{Stringstr="";SOAPConnectionsoapConnection=null;try{//创建实际的(actual)消息对象,通过messagfactory来创建MessageFactorymessageFactory=MessageFactory.newInstance();SOAPMessagemessage=messageFactory.createMessage();//建立messagepart对象SOAPPartsoapPart=message.getSOAPPart();//建立soapEnvelope对象SOAPEnvelopesoapEnvelope=soapPart.getEnvelope();//建立SOAPBody对象SOAPBodysoapBody=soapEnvelope.getBody();//将对象加入soapsoapBody.addChildElement(Namename)创建使用给定Name对象初始化的新SOAPElement对象,并将该新元素添加到此SOAPElement对象。//soapEnvelope.createName(Stringname)创建使用给定本地名称初始化的新Name对象。SOAPElementbodyElement=soapBody.addChildElement(soapEnvelope.createName(operateFun));//addTextNode(Stringstr)创建使用给定String初始化的新Text对象,并将其添加到此SOAPElement对象。//微信号if(null!=parameter.get("fromUserName")){bodyElement.addChildElement("fromUserName").addTextNode(parameter.get("fromUserName").toString());}//客户号if(null!=parameter.get("clientid")){bodyElement.addChildElement("clientid").addTextNode(parameter.get("clientid").toString());}//关键字if(null!=parameter.get("wordCode")){bodyElement.addChildElement("wordCode").addTextNode(parameter.get("wordCode").toString());}//发送xml消息到核心if(null!=parameter.get("xml")){bodyElement.addChildElement("xml").addTextNode(parameter.get("xml").toString());}message.saveChanges();//getMimeHeaders()以与传输无关的方式返回此SOAPMessage对象所有特定于传输的MIME头。返回MimeHeaders对象//addHeader将带有指定名称和值的MimeHeader对象添加到此MimeHeaders对象的头列表。message.getMimeHeaders().addHeader("SOAPAction","");//建立连接,通过soapconnectionfactory来建立SOAPConnectionFactorysoapConnectionFactory=SOAPConnectionFactory.newInstance();soapConnection=soapConnectionFactory.createConnection();//call(SOAPMessagerequest,Objectto)将给定消息发送到指定端点,在返回应答前将一直阻塞。SOAPMessagereply=soapConnection.call(message,destination);//接口返回if(reply!=null){//返回ODoc//getFirstChild()此节点的第一个子节点。如果没有这样的节点,则返回null。返回node对象//getTextContent()此属性返回此节点及其后代的文本内容。str=reply.getSOAPBody().getFirstChild().getTextContent();}else{str=null;}}catch(Exceptione){e.printStackTrace();}finally{if(null!=soapConnection){soapConnection.close();soapConnection=null;}}returnstr;}
解决方案
解决方案二:
有些疑问不懂.跪求大神给我这个菜鸟解决下.首先这个方法的作用及返回值是什么而且这是什么技术啊是说基于soap的webserivce的技术么?我想搞懂这段代码要学习点什么东西