目前项目用到短信接口,只有一个WSDL文件,怎么写一个客服端发送短信
MsgService.java
package org.example.msgservice;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
/**
* This class was generated by the JAX-WS RI. JAX-WS RI 2.1.3-hudson-390-
* Generated source version: 2.0
*
*/
@WebService(name = "MsgService", targetNamespace = "http://www.example.org/MsgService/")
public interface MsgService {
/**
*
* @param content
* @param checkcode
* @param spid
* @param date
* @param mobile
* @return returns java.lang.String
*/
@WebMethod(action = "http://www.example.org/MsgService/NewOperation")
@WebResult(name = "status", targetNamespace = "")
@RequestWrapper(localName = "sendMsg", targetNamespace = "http://www.example.org/MsgService/", className = "org.example.msgservice.SendMsg")
@ResponseWrapper(localName = "sendMsgResponse", targetNamespace = "http://www.example.org/MsgService/", className = "org.example.msgservice.SendMsgResponse")
public String sendMsg(
@WebParam(name = "spid", targetNamespace = "") String spid,
@WebParam(name = "date", targetNamespace = "") String date,
@WebParam(name = "checkcode", targetNamespace = "") String checkcode,
@WebParam(name = "mobile", targetNamespace = "") String mobile,
@WebParam(name = "content", targetNamespace = "") String content);
}
MsgServiceSOAPImpl.java
package org.example.msgservice;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
import sun.misc.BASE64Encoder;
import com.test.Demo;
@javax.jws.WebService(endpointInterface = "org.example.msgservice.MsgService", targetNamespace = "http://www.example.org/MsgService/", serviceName = "MsgService", portName = "MsgServiceSOAP")
public class MsgServiceSOAPImpl {
public String sendMsg(String spid, String date, String checkcode,
String mobile, String content) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Not implemented yet.");
}
}
ObjectFactory.java
package org.example.msgservice;
import javax.xml.bind.annotation.XmlRegistry;
/**
* This object contains factory methods for each Java content interface and Java
* element interface generated in the org.example.msgservice package.
* <p>
* An ObjectFactory allows you to programatically construct new instances of the
* Java representation for XML content. The Java representation of XML content
* can consist of schema derived interfaces and classes representing the binding
* of schema type definitions, element declarations and model groups. Factory
* methods for each of these are provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
/**
* Create a new ObjectFactory that can be used to create new instances of
* schema derived classes for package: org.example.msgservice
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link SendMsgResponse }
*
*/
public SendMsgResponse createSendMsgResponse() {
return new SendMsgResponse();
}
/**
* Create an instance of {@link SendMsg }
*
*/
public SendMsg createSendMsg() {
return new SendMsg();
}
}
package-info.java
@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.example.org/MsgService/")
package org.example.msgservice;
SendMsg.java
package org.example.msgservice;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>
* Java class for anonymous complex type.
*
* <p>
* The following schema fragment specifies the expected content contained within
* this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="spid" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="date" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="checkcode" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="mobile" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="content" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = { "spid", "date", "checkcode", "mobile",
"content" })
@XmlRootElement(name = "sendMsg")
public class SendMsg {
@XmlElement(required = true)
protected String spid;
@XmlElement(required = true)
protected String date;
@XmlElement(required = true)
protected String checkcode;
@XmlElement(required = true)
protected String mobile;
@XmlElement(required = true)
protected String content;
/**
* Gets the value of the spid property.
*
* @return possible object is {@link String }
*
*/
public String getSpid() {
return spid;
}
/**
* Sets the value of the spid property.
*
* @param value
* allowed object is {@link String }
*
*/
public void setSpid(String value) {
this.spid = value;
}
/**
* Gets the value of the date property.
*
* @return possible object is {@link String }
*
*/
public String getDate() {
return date;
}
/**
* Sets the value of the date property.
*
* @param value
* allowed object is {@link String }
*
*/
public void setDate(String value) {
this.date = value;
}
/**
* Gets the value of the checkcode property.
*
* @return possible object is {@link String }
*
*/
public String getCheckcode() {
return checkcode;
}
/**
* Sets the value of the checkcode property.
*
* @param value
* allowed object is {@link String }
*
*/
public void setCheckcode(String value) {
this.checkcode = value;
}
/**
* Gets the value of the mobile property.
*
* @return possible object is {@link String }
*
*/
public String getMobile() {
return mobile;
}
/**
* Sets the value of the mobile property.
*
* @param value
* allowed object is {@link String }
*
*/
public void setMobile(String value) {
this.mobile = value;
}
/**
* Gets the value of the content property.
*
* @return possible object is {@link String }
*
*/
public String getContent() {
return content;
}
/**
* Sets the value of the content property.
*
* @param value
* allowed object is {@link String }
*
*/
public void setContent(String value) {
this.content = value;
}
}
SendMsgResponse.java
package org.example.msgservice;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>
* Java class for anonymous complex type.
*
* <p>
* The following schema fragment specifies the expected content contained within
* this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="status" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = { "status" })
@XmlRootElement(name = "sendMsgResponse")
public class SendMsgResponse {
@XmlElement(required = true)
protected String status;
/**
* Gets the value of the status property.
*
* @return possible object is {@link String }
*
*/
public String getStatus() {
return status;
}
/**
* Sets the value of the status property.
*
* @param value
* allowed object is {@link String }
*
*/
public void setStatus(String value) {
this.status = value;
}
}
转成6个java文件,我应该调用哪个类的方法来发短信
[解决办法]
上面的代码是根据wsdl生成的??在开发发工具中
[解决办法]
上面的代码是根据wsdl生成的??在开发发工具中可以根据wsdl直接生成客户端的
[解决办法]
楼主用wsdl转的6个java是用来发布webservice服务的,也就说是用来提供给别人调用的,刚好搞反了
可以用下面代码测试、参考下
public class SAAJClientTest { public static final String NAMESPACE_URI = "http://www.example.org/MsgService/"; public static final String PREFIX = "tns"; private SOAPConnectionFactory connectionFactory; private MessageFactory messageFactory; private URL url; public SAAJClientTest(String url) throws SOAPException, MalformedURLException { connectionFactory = SOAPConnectionFactory.newInstance(); messageFactory = MessageFactory.newInstance(); this.url = new URL(url); } private SOAPMessage createHelloRequest() throws SOAPException { SOAPMessage message = messageFactory.createMessage(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); Name helloRequestName = envelope.createName("sendMsg", PREFIX, NAMESPACE_URI); SOAPBodyElement helloRequestElement = message.getSOAPBody().addBodyElement(helloRequestName); helloRequestElement.addChildElement("spid").setTextContent("xxx"); helloRequestElement.addChildElement("date").setTextContent("2012-08-23"); helloRequestElement.addChildElement("checkcode").setTextContent("xxx"); helloRequestElement.addChildElement("mobile").setTextContent("136xxxxxxxx"); helloRequestElement.addChildElement("content").setTextContent("i like 2 say!"); return message; } public void callWebService() throws SOAPException, IOException { SOAPMessage request = createHelloRequest(); SOAPConnection connection = connectionFactory.createConnection(); SOAPMessage response = connection.call(request, url); if (response.getSOAPBody().hasFault()) { SOAPFault fault = response.getSOAPBody().getFault(); System.err.println("Received SOAP Fault"); System.err.println("SOAP Fault Code :" + fault.getFaultCode()); System.err.println("SOAP Fault String :" + fault.getFaultString()); }else{ System.out.println("发送成功"); } } public static void main(String[] args) throws Exception { String url = "http://www.example.org/MsgService/"; SAAJClientTest helloClient = new SAAJClientTest(url); helloClient.callWebService(); } }
[解决办法]
去要短信接口的样例代码,他们提供的。
[解决办法]
都给了WSDL了,自然是用工具生成客户端代理,然后直接用了~干嘛还要发数据报
WS明显的就是屏蔽通讯细节的,使得在分布式环境下,各系统之间功能的调用就跟在本地一样
你在搞个HTTP什么的,WebService还有什么意义
[解决办法]