import java.util.Set; import java.util.Vector;import org.apache.soap.Constants; import org.apache.soap.Fault; import org.apache.soap.SOAPException; import org.apache.soap.rpc.Call; import org.apache.soap.rpc.Parameter; import org.apache.soap.rpc.Response;public class WebServiceUtil { public static String getService(String requesturl,Map parameters) { URL url = null; try { url=new URL(requesturl); } catch (MalformedURLException mue) { return mue.getMessage(); } // This is the main SOAP object Call soapCall = new Call(); // Use SOAP encoding //http://appkey.imjuju.com:8200/api/chatmanage.asmx/UserLogin //?loginname=no1&loginpwd=123456&lat=1213&lng=79 //soapCall.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encoding/"); soapCall.setEncodingStyleURI( Constants.NS_URI_SOAP_ENC); // This is the remote object we're asking for the price soapCall.setTargetObjectURI("urn:xmethods-ChatManage"); // This is the name of the method on the above object soapCall.setMethodName("UserLogin"); // We need to send the ISBN number as an input parameter to the method Vector soapParams = new Vector(); // name, type, value, encoding style if(parameters!=null){ Set<String> set = parameters.keySet(); Parameter isbnParam = null; for(String key:set){ isbnParam = new Parameter(key, String.class, parameters.get(key),null); soapParams.addElement(isbnParam); } } soapCall.setParams(soapParams); try { // Invoke the remote method on the object Response soapResponse = soapCall.invoke(url,""); // Check to see if there is an error, return "N/A" if (soapResponse.generatedFault()) { Fault fault = soapResponse.getFault(); String f = fault.getFaultString(); return f; } else { // read result Parameter soapResult = soapResponse.getReturnValue (); // get a string from the result return soapResult.getValue().toString(); } } catch (SOAPException se) { return se.getMessage(); } }
public static void main(String[] args) { String url ="http://appkey.imjuju.com:8200/api/chatmanage.asmx"; Map<String,String> parameters = new HashMap<String, String>(); parameters.put("loginname", "no1"); parameters.put("loginpwd","123456"); parameters.put("lat","123456"); parameters.put("lng","123456"); String a = getService(url, parameters); System.out.println(a); } }一样的错误: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: . at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
http://appkey.imjuju.com:8200/api/chatmanage.asmx
访问的 UserLogin
文件地址:
http://appkey.imjuju.com:8200/api/chatmanage.asmx
访问的 UserLogin
import java.util.Vector;import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.SOAPException;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;public class WebServiceUtil {
public static String getService(String requesturl,Map parameters) {
URL url = null;
try {
url=new URL(requesturl);
} catch (MalformedURLException mue) {
return mue.getMessage();
}
// This is the main SOAP object
Call soapCall = new Call();
// Use SOAP encoding
//http://appkey.imjuju.com:8200/api/chatmanage.asmx/UserLogin
//?loginname=no1&loginpwd=123456&lat=1213&lng=79
//soapCall.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encoding/");
soapCall.setEncodingStyleURI( Constants.NS_URI_SOAP_ENC);
// This is the remote object we're asking for the price
soapCall.setTargetObjectURI("urn:xmethods-ChatManage");
// This is the name of the method on the above object
soapCall.setMethodName("UserLogin");
// We need to send the ISBN number as an input parameter to the method
Vector soapParams = new Vector();
// name, type, value, encoding style
if(parameters!=null){
Set<String> set = parameters.keySet();
Parameter isbnParam = null;
for(String key:set){
isbnParam = new Parameter(key, String.class, parameters.get(key),null);
soapParams.addElement(isbnParam);
}
}
soapCall.setParams(soapParams);
try {
// Invoke the remote method on the object
Response soapResponse = soapCall.invoke(url,"");
// Check to see if there is an error, return "N/A"
if (soapResponse.generatedFault()) {
Fault fault = soapResponse.getFault();
String f = fault.getFaultString();
return f;
} else {
// read result
Parameter soapResult = soapResponse.getReturnValue ();
// get a string from the result
return soapResult.getValue().toString();
}
} catch (SOAPException se) {
return se.getMessage();
} }
public static void main(String[] args) {
String url ="http://appkey.imjuju.com:8200/api/chatmanage.asmx";
Map<String,String> parameters = new HashMap<String, String>();
parameters.put("loginname", "no1");
parameters.put("loginpwd","123456");
parameters.put("lat","123456");
parameters.put("lng","123456");
String a = getService(url, parameters);
System.out.println(a);
}
}一样的错误:
System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: .
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
public void testUserLogin(){
try {
String methodName = "UserLogin";
String userName = "no1";
String passWord = "123456";
float lat = 1.2f;
float lng = 1.20f;
String url = "http://appkey.imjuju.com:8200/api/chatmanage.asmx?wsdl";
Client client = new Client(new URL(url));
Object[] resultInfo = client.invoke(methodName,new Object[]{userName,passWord,lat,lng});
if (null != resultInfo && resultInfo.length > 0) {
System.out.println(resultInfo[0]);
}
} catch (Exception e) {
e.printStackTrace();
}
}