关于安卓调用wcf的一些问题

最近公司有个项目需要和别的系统做对接,对方开放的是webservice接口,搞了很久终于搞出来了,在此记录一下

获取数据的service

public class SoapService implements ISoapService {
   
    private static final String NAMESPACE = "http://tempuri.org/";
   
    private static final String METHODNAME = "GetOrder";
   
    private static final String URL = "http://192.168.2.22/JTE.Server/ThirdpartyService";
    
    private static final String SOAPACTION = "http://tempuri.org/IThirdpartyService/GetOrder";
    private String name;

    public SoapService(String _name) {
        this.name = _name;
    }

    public SoapObject HelloWorldResult() {
        SoapObject result = null;
        SoapObject soapObject = new SoapObject(NAMESPACE, METHODNAME);
        soapObject.addProperty("message", "HOTEL14776379671005");// ���Σ���ס�����������WCF�����еIJ�����һ��
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.bodyOut = soapObject;
        envelope.dotNet = true;
        envelope.setOutputSoapObject(soapObject);
        HttpTransportSE transportSE = new HttpTransportSE(URL);
        transportSE.debug = true;// ʹ�õ�ʽ����
        try {
            transportSE.call(SOAPACTION, envelope);
            result = (SoapObject) envelope.bodyIn;
        } catch (Exception e) {
            String exceptionString = e.toString();
        }
        return result;
    }
}
接口
public interface ISoapService {
    SoapObject HelloWorldResult();
}
 
    

获取代码

SoapService soapService = new SoapService("HOTEL1477637967" + Tools.ROOM_NUMBER + "");
            SoapObject soapObject = soapService.HelloWorldResult();
            String result = soapObject == null ? "网络连接失败!" : soapObject.getProperty(0).toString();

中间还需要一个jar包ksoap2,不知道怎么上传

在这过程中遇到一些坑
1.开发文档中说明有些节点可以为空,然后我就节点名都不写了,最后当然就获取不到数据了。后来还是问他们的开发人员才缓过来
2.曾经我天真的以为java能用的代码,安卓就一定可以用,但是我用wsdl2生成了java的相关代码,并且成功的获取到了数据,但是导入到安卓项目中才发现,报错,noclassdefound,解决不了 ,于是想别的办法
3.我从开始到现在没明白wcf是个什么东西0.0

 

转载于:https://www.cnblogs.com/eiter/p/7122616.html

你可能感兴趣的:(移动开发,java)