[英]Error in Callin Java webservice from Android using k-Soap
I have a created a simple Login Webservice in Java and I am calling it from the Android code. 我在Java中创建了一个简单的登录Web服务,我从Android代码中调用它。 I am passing two String Parameters to the Webservice.
我将两个字符串参数传递给Webservice。 But they become null in the Webservice.
但它们在Webservice中变为null。
WebService Code :
public boolean authenicateUser(@WebParam(name="username")String username,
@WebParam(name="password")String password) {
System.out.println("Inside Authenticae USER+=========="+name+"-----"+Password);//This becomes null and null
final String LOGIN_SQL="SELECT * FROM UserDetails WHERE UserName=? and Password=?";
The Web service is hosted on Localhost Tomcat server Web服务托管在Localhost Tomcat服务器上
Android Server Request :
private static String NAMESPACE = "http://src.AndroidExample.Nagesh.com/";
private static String URL = "http://192.168.56.1:8080/AndroidLoginWS/LoginWebService?wsdl";
private static String SOAP_ACTION = "http://src.AndroidExample.Nagesh.com/";
Systerequest=new SoapObject(NAMESPACE,WebMethodName);
System.out.println("Values before calling WS"+user.UserName+"------"+user.Password);
request.addProperty("username", user.UserName);
request.addProperty("password",user.Password);
return request;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION + WebMethodName, envelope);
System.out.println("INside InvokeLoginWS==========RETURNED.................");
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
loginStatus = Boolean.parseBoolean(response.toString());
The WSDL file is : WSDL文件是:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!--
Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b.
-->
<!--
Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b.
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://src.AndroidExample.Nagesh.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://src.AndroidExample.Nagesh.com/" name="LoginService">
<types>
<xsd:schema>
<xsd:import namespace="http://src.AndroidExample.Nagesh.com/" schemaLocation="http://192.168.56.1:8080/AndroidLoginWS/LoginWebService?xsd=1"/>
</xsd:schema>
</types>
<message name="register">
<part name="parameters" element="tns:register"/>
</message>
<message name="registerResponse">
<part name="parameters" element="tns:registerResponse"/>
</message>
<message name="authenicateUser">
<part name="parameters" element="tns:authenicateUser"/>
</message>
<message name="authenicateUserResponse">
<part name="parameters" element="tns:authenicateUserResponse"/>
</message>
<portType name="LoginMethods">
<operation name="register">
<input wsam:Action="http://src.AndroidExample.Nagesh.com/LoginMethods/registerRequest" message="tns:register"/>
<output wsam:Action="http://src.AndroidExample.Nagesh.com/LoginMethods/registerResponse" message="tns:registerResponse"/>
</operation>
<operation name="authenicateUser">
<input wsam:Action="http://src.AndroidExample.Nagesh.com/LoginMethods/authenicateUserRequest" message="tns:authenicateUser"/>
<output wsam:Action="http://src.AndroidExample.Nagesh.com/LoginMethods/authenicateUserResponse" message="tns:authenicateUserResponse"/>
</operation>
</portType>
<binding name="LoginWSPortBinding" type="tns:LoginMethods">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="register">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="authenicateUser">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="LoginService">
<port name="LoginWSPort" binding="tns:LoginWSPortBinding">
<soap:address location="http://192.168.56.1:8080/AndroidLoginWS/LoginWebService"/>
</port>
</service>
</definitions>
I am new to both Android and Creating Web Service. 我是Android和Creating Web Service的新手。 I tried many other solution.
我尝试了很多其他解决方案 But it does not seems to work.
但它似乎不起作用。
I found the anser for the question. 我找到了问题的解决方案。 I opened the xsd schema from the wdsl.
我从wdsl打开了xsd架构。 It was having the parameters as arg0 and arg1 only,though I have given the @WebParam annotation.
虽然我已经给出了@WebParam注释,但它的参数只有arg0和arg1。 I changed it in the request, the parameter is getting passed correctly.
我在请求中更改了它,参数正确传递。
final String LOGIN_SQL="SELECT * FROM UserDetails WHERE UserName=? and Password=?";
request.addProperty("name", user.UserName);
request.addProperty("Password",user.Password);
// try to change name to UserName //尝试将名称更改为UserName
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.