2 kingson wu Kingson_Wu 于 2013.11.18 19:46 提问

Android用ksoap2调用WCF的问题,详细如代码。

用Java和WCF框架实现了一个Webservice,在浏览器中输入http://localhost:9999/cat?wsdl
得到:
//--------------------------------------------------

/wsdl:import






/wsdl:input


/wsdl:output
/wsdl:operation




/wsdl:input


/wsdl:output
/wsdl:operation
/wsdl:binding



/wsdl:port
/wsdl:service
/wsdl:definitions

//---------------------------------------------
然后ksoap2实现客户端调用代码:

package kxw;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
public class Test {

//命名空间  
private static final String NAMESPACE = "http://ws.cxf.kxw.org/";  
//Service地址  
private static final String URL = "http://localhost:9999/cat/HelloWorld.svc";

//需要调用的方法名  
private static final String METHOD= "sayHi";

//方法对应的Action
private static final String ACTION = "http://ws.cxf.kxw.org/cat/HelloWorld/sayHi";

public static void main(String[] args) {        
    //ISoapService service = new ISoapService("Torres");        
//  SoapObject result = service.LoadResult();                
//  System.out.println("WCF返回的数据是:" + result.getProperty(0));  

    System.out.print( testWCF("Ronaldo"));



}
 public static String  testWCF(String kxw)  {

        String result ="kxw";
    try {  


        //1.实例化SoapObject对象  
        SoapObject request = new SoapObject(NAMESPACE, METHOD);  
        //2.如果方法需要参数,设置参数  
        request.addProperty("arg0", kxw);
       // request.addProperty("strPassWordMd5", strPassWordMd5);
        //3.设置Soap的请求信息,参数部分为Soap协议的版本号  

        System.out.println("----------------");
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);  
        envelope.bodyOut=request;
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);     

        //4.构建传输对象  
        HttpTransportSE transport = new HttpTransportSE(URL);  
        transport.debug = true;               
        //5.访问WebService,第一个参数为调用方法的Aciton,第二个参数为Envelope对象  

        System.out.println("----------------");
        transport.call(ACTION, envelope); 

        System.out.printf("success!\n");
        //6.解析返回的数据  
     //  result = envelope.getResponse().toString();

    System.out.print( envelope.getResponse().toString()+"-----------");
}   catch (IOException e) {  

} catch (XmlPullParserException e) {  

}  
return result;

    }

}


1、 private static final String URL = "http://localhost:9999/cat/HelloWorld.svc";
改为:http://localhost:9999/cat/HelloWorld或者http://localhost:9999/cat

2、 private static final String ACTION = "http://ws.cxf.kxw.org/cat/HelloWorld/sayHi";改为http://ws.cxf.kxw.org/cat/sayHi

以上情况都是失败,请问有哪位大哥知道该怎么弄?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!