我正在尝试从Android客户端调用2个函数setUserName()和setPassword()使用ksoap2来检查用户登录:
public void setPassword(String password) {
this.password = password;
}
public void setUserName(String userName)
{
this.userName = userName;
}
public boolean isCorrect(){
if(this.userName.equals("abc") && this.password.equals("xyz"))
return true;
else
return false;
}
在客户端应用程序上我想setUserName()和setPassword()然后调用isCorrect()函数,但我没有成功。当我调用isCorrect()时,用户名和密码仍为空。
androidHttpTransport.call(SOAP_ACTION+"setUserId", envelope);
androidHttpTransport.call(SOAP_ACTION+"setPassword", envelope);
androidHttpTransport.call(SOAP_ACTION+"isCorrect", envelope);
请告诉我这个案子的解决方案。 谢谢,
添加更多代码:
SoapObject request = new SoapObject(NAMESPACE, "setUserName");
// Set Username
PropertyInfo unamePI = new PropertyInfo();
unamePI.setName("userName");
unamePI.setValue(userName);
unamePI.setType(String.class);
request.addProperty(unamePI);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION+"setUserName", envelope);
} catch (Exception e) {
e.printStackTrace();
}
request = new SoapObject(NAMESPACE, "setPassword");
// Set Password
PropertyInfo passPI = new PropertyInfo();
passPI.setName("password");
passPI.setValue(password);
passPI.setType(String.class);
request.addProperty(passPI);
envelope.setOutputSoapObject(request);
try {
androidHttpTransport.call(SOAP_ACTION+"setPassword", envelope);
} catch (Exception e) {
e.printStackTrace();
}
request = new SoapObject(NAMESPACE, "isCorrect");
envelope.setOutputSoapObject(request);
try {
androidHttpTransport.call(SOAP_ACTION+"isCorrect", envelope);
// Get the response
Object response = envelope.getResponse();
} catch (Exception e) {
e.printStackTrace();
}
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://ws.webapp.org" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://ws.webapp.org">
<wsdl:documentation>
Please Type your service description here
</wsdl:documentation>
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://ws.webapp.org">
<xs:element name="setUserName">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="userName" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="setPassword">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="password" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="isCorrect">
<xs:complexType>
<xs:sequence/>
</xs:complexType>
</xs:element>
<xs:element name="isCorrectResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getUserName">
<xs:complexType>
<xs:sequence/>
</xs:complexType>
</xs:element>
<xs:element name="getUserNameResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getPassword">
<xs:complexType>
<xs:sequence/>
</xs:complexType>
</xs:element>
<xs:element name="getPasswordResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="getUserNameRequest">
<wsdl:part name="parameters" element="ns:getUserName"/>
</wsdl:message>
<wsdl:message name="getUserNameResponse">
<wsdl:part name="parameters" element="ns:getUserNameResponse"/>
</wsdl:message>
<wsdl:message name="setUserNameRequest">
<wsdl:part name="parameters" element="ns:setUserName"/>
</wsdl:message>
<wsdl:message name="getPasswordRequest">
<wsdl:part name="parameters" element="ns:getPassword"/>
</wsdl:message>
<wsdl:message name="getPasswordResponse">
<wsdl:part name="parameters" element="ns:getPasswordResponse"/>
</wsdl:message>
<wsdl:message name="setPasswordRequest">
<wsdl:part name="parameters" element="ns:setPassword"/>
</wsdl:message>
<wsdl:message name="isCorrectRequest">
<wsdl:part name="parameters" element="ns:isCorrect"/>
</wsdl:message>
<wsdl:message name="isCorrectResponse">
<wsdl:part name="parameters" element="ns:isCorrectResponse"/>
</wsdl:message>
<wsdl:portType name="HelloPortType">
<wsdl:operation name="getUserName">
<wsdl:input message="ns:getUserNameRequest" wsaw:Action="urn:getUserName"/>
<wsdl:output message="ns:getUserNameResponse" wsaw:Action="urn:getUserNameResponse"/>
</wsdl:operation>
<wsdl:operation name="setUserName">
<wsdl:input message="ns:setUserNameRequest" wsaw:Action="urn:setUserName"/>
</wsdl:operation>
<wsdl:operation name="getPassword">
<wsdl:input message="ns:getPasswordRequest" wsaw:Action="urn:getPassword"/>
<wsdl:output message="ns:getPasswordResponse" wsaw:Action="urn:getPasswordResponse"/>
</wsdl:operation>
<wsdl:operation name="setPassword">
<wsdl:input message="ns:setPasswordRequest" wsaw:Action="urn:setPassword"/>
</wsdl:operation>
<wsdl:operation name="isCorrect">
<wsdl:input message="ns:isCorrectRequest" wsaw:Action="urn:isCorrect"/>
<wsdl:output message="ns:isCorrectResponse" wsaw:Action="urn:isCorrectResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloSoap11Binding" type="ns:HelloPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="getUserName">
<soap:operation soapAction="urn:getUserName" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="setUserName">
<soap:operation soapAction="urn:setUserName" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="getPassword">
<soap:operation soapAction="urn:getPassword" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="setPassword">
<soap:operation soapAction="urn:setPassword" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="isCorrect">
<soap:operation soapAction="urn:isCorrect" 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="HelloSoap12Binding" type="ns:HelloPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="getUserName">
<soap12:operation soapAction="urn:getUserName" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="setUserName">
<soap12:operation soapAction="urn:setUserName" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="getPassword">
<soap12:operation soapAction="urn:getPassword" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="setPassword">
<soap12:operation soapAction="urn:setPassword" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="isCorrect">
<soap12:operation soapAction="urn:isCorrect" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="HelloHttpBinding" type="ns:HelloPortType">
<http:binding verb="POST"/>
<wsdl:operation name="getUserName">
<http:operation location="getUserName"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="setUserName">
<http:operation location="setUserName"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="getPassword">
<http:operation location="getPassword"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="setPassword">
<http:operation location="setPassword"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="isCorrect">
<http:operation location="isCorrect"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Hello">
<wsdl:port name="HelloHttpSoap11Endpoint" binding="ns:HelloSoap11Binding">
<soap:address location="http://localhost:8080/testwebservice/services/Hello.HelloHttpSoap11Endpoint/"/>
</wsdl:port>
<wsdl:port name="HelloHttpSoap12Endpoint" binding="ns:HelloSoap12Binding">
<soap12:address location="http://localhost:8080/testwebservice/services/Hello.HelloHttpSoap12Endpoint/"/>
</wsdl:port>
<wsdl:port name="HelloHttpEndpoint" binding="ns:HelloHttpBinding">
<http:address location="http://localhost:8080/testwebservice/services/Hello.HelloHttpEndpoint/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
答案 0 :(得分:0)
为不同的方法适当地设置Action作为Namspace / Action或者你现在设置setUserName SOAP_ACTION所遵循的任何方法。
根据你的wsdl,
for setUserName,
SOAP_ACTION="http://ws.webapp.org/setUserName";
用于setPassword。
SOAP_ACTION="http://ws.webapp.org/setPassword";
表示isCorrect
SOAP_ACTION = “http://ws.webapp.org/isCorrect”;