最近有一个任务,即调用第三方的 webService 接口,实现发送短信功能. 现在第三方只给了我一个 wsdl 描述文件,里面有各种操作接口,我想在我的方法中调用一下webservice接口,发送短信,但是我不知道怎么写啊。我只有一个这个地址 http://134.224.102.6:80/CompanySendSmInf/services/SmsInf?wsdl 和一些接口中方法的说明,但是我怎么操作啊,请明白人指点下. 另外我按照网上的一些方法,连接上面的地址时,报连接超时异常: AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.net.ConnectException: Connection timed out: connect
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) 第三方提供了用户名和密码,但不知道怎样设置使用,请高人指点下操作流程: 即怎样利用这个连接地址及所给的 wsdl 描述文件,来调用相关的接口,实现发送短信功能.
解决方案 »
- 如何解决java.lang.IllegalStateException:getAttribute: Session already invalidated这个问题啊
- 求 webwork+连接池 例子
- 关于文件上传最大容量的问题!!
- Lucene应用中单关键字的命中率好象不对,怎么解决(即刻给分)
- 一个jsp+javabean的问题,在线急急急!!!!!!!!!!!!!!!!
- 哪有eclipse S-3.0M7-200402122000 版的中文语言包下载,下载后怎么使用?
- ajax+struct2结合起来实现分页,出现问题了
- 初学者,请高手指教!
- Tomcat3.3中中文问题
- Ext时间控件精确到年或者是年月问题
- dom4j解析xml字符串在google浏览器下报错的问题
- 关于Hibernate 与数据库查询问题。
这是个内网地址吧,WEBSERVICE 还要用户名密码 我还真不知道。
你有了wsdl文件 直接就可以用ECLIPSE 生成客户端的我建议你还是先在 你的浏览器上访问 http://134.224.102.6:80/CompanySendSmInf/services 看他的WEBSERVICE
到底开着没
第一、根据http://134.224.102.6:80/CompanySendSmInf/services/SmsInf?wsdl 拿到WSDL文件。
第二、根据Axis的jar包,把WSDL文件生成客服端java代码。(可以把java文件打成jar文件,便于管理。怎么生成java代码,百度里都有说明我就不写了。)
第三、在你工程里用AXIS的功能属性,调用外部接口;给你一个格式模板:
MobileCodeWSLocator l=new MobileCodeWSLocator();//MobileCodeWSLocator是WSDL文件生成客服端java类;
MobileCodeWSSoap s=l.getMobileCodeWSSoap();();//MobileCodeWSSoap 是WSDL文件生成客服端java类 String m=s.getMobileCodeInfo("13811534742", "");
如果你用Axis生成的java类,格式和上面一样;自己参考一下就懂了。你上面明显的连接异常,第三方服务明显没有开,WEBSERVICE可以设置户名、密码,像我们行所有的WEBSERVICE都设置,安全考虑吧。还有不懂的可以call我。
try {
org.apache.axis.client.Call _call = super._createCall();
if (super.maintainSessionSet) {
_call.setMaintainSession(super.maintainSession);
}
if (super.cachedUsername != null) {
_call.setUsername(super.cachedUsername);
}
if (super.cachedPassword != null) {
_call.setPassword(super.cachedPassword);
}
if (super.cachedEndpoint != null) {
_call.setTargetEndpointAddress(super.cachedEndpoint);
}
if (super.cachedTimeout != null) {
_call.setTimeout(super.cachedTimeout);
}
if (super.cachedPortName != null) {
_call.setPortName(super.cachedPortName);
}
java.util.Enumeration keys = super.cachedProperties.keys();
while (keys.hasMoreElements()) {
java.lang.String key = (java.lang.String) keys.nextElement();
_call.setProperty(key, super.cachedProperties.get(key));
}
// All the type mapping information is registered
// when the first call is made.
// The type mapping information is actually registered in
// the TypeMappingRegistry of the service, which
// is the reason why registration is only needed for the first call.
synchronized (this) {
if (firstCall()) {
// must set encoding style before registering serializers
_call.setEncodingStyle(null);
for (int i = 0; i < cachedSerFactories.size(); ++i) {
java.lang.Class cls = (java.lang.Class) cachedSerClasses.get(i);
javax.xml.namespace.QName qName =
(javax.xml.namespace.QName) cachedSerQNames.get(i);
java.lang.Object x = cachedSerFactories.get(i);
if (x instanceof Class) {
java.lang.Class sf = (java.lang.Class)
cachedSerFactories.get(i);
java.lang.Class df = (java.lang.Class)
cachedDeserFactories.get(i);
_call.registerTypeMapping(cls, qName, sf, df, false);
}
else if (x instanceof javax.xml.rpc.encoding.SerializerFactory) {
org.apache.axis.encoding.SerializerFactory sf = (org.apache.axis.encoding.SerializerFactory)
cachedSerFactories.get(i);
org.apache.axis.encoding.DeserializerFactory df = (org.apache.axis.encoding.DeserializerFactory)
cachedDeserFactories.get(i);
_call.registerTypeMapping(cls, qName, sf, df, false);
}
}
}
}
return _call;
}
catch (java.lang.Throwable _t) {
throw new org.apache.axis.AxisFault("Failure trying to get the Call object", _t);
}
}CXF与AXIS都有不同的设置方法,上面是axis的源码,设置的东西还是比较多的,怎么设置网上有方法,我没过多研究过。一般都不会去设置。