参照网上的代码如下:
package test;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class Test { 
public static void main(String[] args) { 
String[] orderinfo=new String[1]; 
orderinfo[0]="上海";
String str = ""; 
try { 
String url = "http://webservice.xp81.com/AspxTools.asmx"; 
Service service = new Service(); 
Call call = (Call) service.createCall(); 
call.setTargetEndpointAddress(new java.net.URL(url)); 
call.setOperationName(new QName("http://tempuri.org", "GetSystem"));
call.addParameter("strUrl",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.setUseSOAPAction(true); 
call.setSOAPActionURI("http://tempuri.org/IsURL"); 
str = (String) call.invoke(new Object[]{orderinfo}); 
} catch (Exception e) { 
System.out.println("asdf"); 
e.printStackTrace(); 

System.out.println(str); 

}
总是报异常  似乎是参数没有传递过去,换了几个webservice都是这样的错误。
请大家帮看看怎么解决,谢谢,这个地址是外网可用的,大家可以测试代码!

解决方案 »

  1.   

    地址对不?
    参数是否在c#中定义啦。
    对方的webservice是否开启
      

  2.   

    从来都是获取WSDL文件,用ECLIPSE的axis插件生成客户端代码,调用,从来没有出现过问题。
      

  3.   

    看看我的这个,谁帮帮我呀!!!http://topic.csdn.net/u/20091124/10/266660ad-23da-46bb-acdc-680b9cee6470.html
      

  4.   

    new QName("http://tempuri.org", "GetSystem");
    曾经碰到过Java调用C#的webservice的问题,关键在于申明QName的方式上,写的不对就会传不出去参数,而且如果你能够观察http传输流,可以很明显看出不同的QName申明方式生成的XML是不同的,这个好象是Axis的Bug。
    具体咋写,让我回去查查你可以用http injection之类的工具,先登陆C#服务器的Test页面测试下,然后看发送的真实XML与你Axis生成的XML的区别,非常明显。
      

  5.   

    谢谢楼上,问题是webservice第三方的,我无法测试他们的东西
    等你的代码了,谢谢
      

  6.   

    另外,抱歉我上面的代码有一行贴错了,修正为以下
    call.setOperationName(new QName("http://tempuri.org", "GetSystem")); 
    修正为:
    call.setOperationName(new QName("http://tempuri.org", "IsURL")); 
      

  7.   

    call.addParameter("strUrl",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN); 
    问题可能出在这句上。
    我以前写代码自己封装了一下。 /**
     * 
     * @param methodName 执行的方法名
     * @param paremate 参数数据数组
     * @param qNameList 变量命名空间List
     * @param actionUrl soapActionUrl
     * @return
     */
    public Object invokeMehodWithParemate(String methodName, Object[] paremate, List qNameList, String actionUrl){
    String endPoint = this.getSERVICE_URL();
    Object returnObj = null;
    try{
    Service service = new Service();
    Call call = null;
    call = (Call)service.createCall(); QName qName = new QName(this.NAME_SPACE,methodName); 
    call.setOperationName(qName);
    call.setSOAPActionURI(actionUrl);

    for(int i=0;i<qNameList.size();i++){
    call.addParameter((QName)qNameList.get(i), org.apache.axis.encoding.XMLType.XSD_STRING,
    javax.xml.rpc.ParameterMode.IN);

    }
    call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
    call.setTargetEndpointAddress(new URL(endPoint)); 
    returnObj = call.invoke(paremate);

    }catch(Exception ie){
    ie.printStackTrace();
    }
    return returnObj;
    }
    红色的部分,你试试,addParemate的时候传入的是QName类型,而不是String
      

  8.   

    call.addParameter((QName)qNameList.get(i), org.apache.axis.encoding.XMLType.XSD_STRING,
                            javax.xml.rpc.ParameterMode.IN);
      

  9.   

    补一段调用的代码,应该能看懂意思吧 public String getMainClassName(String mainClassId) {
    String actionUlr = "http://tempuri.org/GetMainClassName";
    Object[] paremate = new Object[] { userName, passWord, mainClassId };
    List qNameList = new ArrayList();

    qNameList.add(new QName(webServiceUtil.getNAME_SPACE(), "UserName"));
    qNameList.add(new QName(webServiceUtil.getNAME_SPACE(), "UserPwd"));
    qNameList.add(new QName(webServiceUtil.getNAME_SPACE(), "MainClassID"));

    String className = (String) webServiceUtil.invokeMehodWithParemate(
    "GetMainClassName", paremate, qNameList, actionUlr);
    return className;
    }
      

  10.   

    谢谢,webServiceUtil.getNAME_SPACE()  这个方法给我看看,怎么写的?
      

  11.   

    这个Name_space是由webservice提供的,不是获得的。
      

  12.   

    对啊,我是问webServiceUtil.getNAME_SPACE()  这个方法是不是你自己定义的,我这里没有这个方法,我想知道webServiceUtil.getNAME_SPACE() 里是什么代码
      

  13.   

    Try this. Thank you.package test; 
    import javax.xml.namespace.QName; 
    import org.apache.axis.client.Call; 
    import org.apache.axis.client.Service; public class Test { 
    public static void main(String[] args) { 
    String[] orderinfo=new String[1]; 
    orderinfo[0]="上海"; 
    String str = ""; 
    try { 
        String url = "http://webservice.xp81.com/AspxTools.asmx"; 
        Service service = new Service(); 
        Call call = (Call) service.createCall(); 
        call.setTargetEndpointAddress(new java.net.URL(url)); 
        call.setOperationName(new QName("http://tempuri.org/", "IsURL")); 
        call.addParameter(new QName("http://tempuri.org/", "strUrl"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); 
        call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);    call.setUseSOAPAction(true); 
        call.setSOAPActionURI("http://tempuri.org/IsURL"); 
        str = (String) call.invoke(orderinfo); } catch (Exception e) { 
        System.out.println("asdf"); 
        e.printStackTrace(); 

        System.out.println(str); 


      

  14.   

    webServiceUtil是我自己封装的工具类,getNAME_SPACE()就是return一个String ,这个String在new WebServiceUtil对象的时候由properties配制文件读进对象内初始化,这个值在webservice的test页上有的。
      

  15.   

    to phyerbarte:谢谢,万分感谢,谢谢你的热心,很感动啊,呵呵。再次感谢。
    to sunshinealways:呵呵,你懂我的意思了,我就是要你这样的方式,谢谢哥们。