java调用c#开发的webservice为什么传入的参数为空,在本地点击调用却可以正常传参,请大侠指点,谢谢!

解决方案 »

  1.   

    因为webservice是一个查询语句,返回一个字符串,传入参数为空,查不到记录,就返回空值了。
      

  2.   

    java调用c#开发的webservice为什么传入的参数为空,在本地点击调用却可以正常传参,请大侠指点,谢谢!这是net的代码
    public class Service : System.Web.Services.WebService
    {
        public Service () {        //如果使用设计的组件,请取消注释以下行 
            //InitializeComponent(); 
        }    [WebMethod]
        public string HelloWorld(string arg0,string arg1) {
            return arg0+"-Hello World-"+arg1;
        }    [WebMethod]
        public string HelloWorld2()
        {
            return  "-Hello ytWorld-";
        }
        
    }java调用的代码
    public static String GetWS2(String s1,String s2)
        {
         String output= "";
         try {
           String endpoint="http://localhost:31380/ws2/Service.asmx";
           Service service = new Service();
           Call call = (Call)service.createCall();
           call.setTargetEndpointAddress(new java.net.URL(endpoint));
           call.setOperationName(new QName("http://tempuri.org","HelloWorld"));
           call.addParameter(new QName("http://tempuri.org","arg0"),org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN); 
           call.addParameter(new QName("http://tempuri.org","arg1"),org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
           
           call.setUseSOAPAction(true);
           call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);      
           
           call.setSOAPActionURI("http://tempuri.org/HelloWorld");
           Object[] s = new Object[]{s1,s2};
           output=(String)call.invoke(new Object[]{"df","fff"});
           System.out.println( "result is " + output + ".");
           
           }
           catch (Exception e) {System.err.println(e.toString());}
           return output;
         }
      

  3.   

    yangfeihu
    谢谢,参数命名空间,我不知道在什么地方查呢,指点下
      

  4.   

    lz可是在本地是正常的?然后
    访问外面的地址,你的webservice地址可能直接点进去?看到一大推接口和xml文件描述?
      

  5.   

    call.setSOAPActionURI("http://tempuri.org/HelloWorld");这句移动到
    Call call = (Call)service.createCall();后面再试一下!
      

  6.   

    temptation99 谢谢
    对,在本地可以正常调用,就是打开http://localhost:31380/ws2/Service.asmx,然后点击一个方法,会出现填写参数值然后点调用,这样是正常的,可是用java远程调用传过去的参数就为空。
    那两句也调换了,依然参数为空
      

  7.   

    访问远程的webservice的地址可能在浏览器里打开?
      

  8.   

    http://localhost:31380/ws2/Service.asmx中localhost换成你的远程可访问的ip了吗
      

  9.   

    这你得看看wsdl里面的内容了,默认参数名我记得是in0,in1之类的,不是arg0,即使webservice自己的参数名叫arg0也不行。
      

  10.   

    换成远程ip可以访问
    我给大家看看WSDL:  <?xml version="1.0" encoding="utf-8" ?> 
    - <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    - <wsdl:types>
    - <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
    - <s:element name="HelloWorld">
    - <s:complexType>
    - <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="arg0" type="s:string" /> 
      <s:element minOccurs="0" maxOccurs="1" name="arg1" type="s:string" /> 
      </s:sequence>
      </s:complexType>
      </s:element>
    - <s:element name="HelloWorldResponse">
    - <s:complexType>
    - <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" /> 
      </s:sequence>
      </s:complexType>
      </s:element>
      </s:schema>
      </wsdl:types>
    - <wsdl:message name="HelloWorldSoapIn">
      <wsdl:part name="parameters" element="tns:HelloWorld" /> 
      </wsdl:message>
    - <wsdl:message name="HelloWorldSoapOut">
      <wsdl:part name="parameters" element="tns:HelloWorldResponse" /> 
      </wsdl:message>
    - <wsdl:portType name="ServiceSoap">
    - <wsdl:operation name="HelloWorld">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">根据产品编号查询产品的价格</wsdl:documentation> 
      <wsdl:input message="tns:HelloWorldSoapIn" /> 
      <wsdl:output message="tns:HelloWorldSoapOut" /> 
      </wsdl:operation>
      </wsdl:portType>
    - <wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
      <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
    - <wsdl:operation name="HelloWorld">
      <soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" /> 
    - <wsdl:input>
      <soap:body use="literal" /> 
      </wsdl:input>
    - <wsdl:output>
      <soap:body use="literal" /> 
      </wsdl:output>
      </wsdl:operation>
      </wsdl:binding>
    - <wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap">
      <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
    - <wsdl:operation name="HelloWorld">
      <soap12:operation soapAction="http://tempuri.org/HelloWorld" style="document" /> 
    - <wsdl:input>
      <soap12:body use="literal" /> 
      </wsdl:input>
    - <wsdl:output>
      <soap12:body use="literal" /> 
      </wsdl:output>
      </wsdl:operation>
      </wsdl:binding>
    - <wsdl:service name="Service">
    - <wsdl:port name="ServiceSoap" binding="tns:ServiceSoap">
      <soap:address location="http://74.1.32.132/ws2/Service.asmx" /> 
      </wsdl:port>
    - <wsdl:port name="ServiceSoap12" binding="tns:ServiceSoap12">
      <soap12:address location="http://74.1.32.132/ws2/Service.asmx" /> 
      </wsdl:port>
      </wsdl:service>
      </wsdl:definitions>
      

  11.   

    你把localhost 换成IP地址 ,应该就可以了,看你好像localhost是固定的,所以只能本地调用
      

  12.   

    都跟你说了,叫你检查参数命名空间了。  非要我写出来。
    参数命名空间http://tempuri.org 改成 http://tempuri.org/  ,  懂了不。  
    call.addParameter(new QName("http://tempuri.org/","arg0"),org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);  
    call.addParameter(new QName("http://tempuri.org/","arg1"),org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
    还不对,过来砍我!
      

  13.   

    跟你解释一下:
    <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
    表示: 元素要带命名空间, 而去命名空间是http://tempuri.org/ 而非http://tempuri.org记得给分
      

  14.   

    我也是这个问题,但是代码完全没有问题,不知道他怎么返回的就是一个 null