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);
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;
}
谢谢,参数命名空间,我不知道在什么地方查呢,指点下
访问外面的地址,你的webservice地址可能直接点进去?看到一大推接口和xml文件描述?
Call call = (Call)service.createCall();后面再试一下!
对,在本地可以正常调用,就是打开http://localhost:31380/ws2/Service.asmx,然后点击一个方法,会出现填写参数值然后点调用,这样是正常的,可是用java远程调用传过去的参数就为空。
那两句也调换了,依然参数为空
我给大家看看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>
参数命名空间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);
还不对,过来砍我!
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
表示: 元素要带命名空间, 而去命名空间是http://tempuri.org/ 而非http://tempuri.org记得给分