java中调用.net webservice出现(400)Bad Request错误
代码如下:
Java code
package com.how.client;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.Constants;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class ClientTest {
public static void main(String[] args) {
String url="http://119.97.200.187/WebServiceJyzx.asmx?wsdl";
String namespace = "http://tempuri.org/";
String methodName = "Getbdxx";
String soapActionURI = "http://tempuri.org/Getbdxx";
Service service = new Service();
try{
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(url));
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapActionURI);
call.setOperationName(new QName(namespace, methodName));
call.addParameter(new QName(namespace,"42010520091124008"),Constants.XSD_STRING,ParameterMode.IN);
call.setReturnType(Constants.XSD_STRING);
String ret = (String) call.invoke(new Object[]{"222"});
System.out.println("返回结果---> " + ret);
}catch(Exception e){
e.printStackTrace();
}
}
}
出现下面的错误:
AxisFault
faultCode: {http://xml.apache.org/axis/}HTTP
faultSubcode:
faultString: (400)Bad Request
faultActor:
faultNode:
faultDetail:
{}:return code: 400
{http://xml.apache.org/axis/}HttpErrorCode:400
(400)Bad Request
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:744)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.how.client.ClientTest.main(ClientTest.java:27)
------解决方案--------------------
楼主,建议你先试用myeclipse自带的webservice客户端工具,看看是不是这个服务本身存在问题。排除这个问题后,再继续和楼主讨论。