最近有一个任务,即调用第三方的 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 描述文件,来调用相关的接口,实现发送短信功能.
    

解决方案 »

  1.   

    http://134.224.102.6:80/CompanySendSmInf/services/SmsInf?wsdl
    这是个内网地址吧,WEBSERVICE 还要用户名密码 我还真不知道。
    你有了wsdl文件 直接就可以用ECLIPSE 生成客户端的我建议你还是先在 你的浏览器上访问 http://134.224.102.6:80/CompanySendSmInf/services 看他的WEBSERVICE
    到底开着没
      

  2.   

    给你一个最简单的方法:
    第一、根据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我。
      

  3.   

    谢谢楼上的热情回复, 我再研究研究, 想问下zouchuangzhi: 如果WEBSERVICE要设置户名、密码,这个一般怎么设?
      

  4.   

    zn85600301: 我在浏览器上访问了 http://134.224.102.6:80/CompanySendSmInf/services 这个地址, 但打不开,可能是第三方把他们的内网地址给我了, 但现在又联系不上他们 ,所以现在在这里向高手请教.
      

  5.   

     protected org.apache.axis.client.Call createCall() throws java.rmi.RemoteException {
            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的源码,设置的东西还是比较多的,怎么设置网上有方法,我没过多研究过。一般都不会去设置。
      

  6.   

    最简单的是使用JDk1.6自带的JAX-WS实现web services
      

  7.   

    根据 WSDL 文件用 AXIS 包来生成客户端代码,然后直接调用,这样确实很快,谢谢大家!