2012-04-04 13 views
3

Guten Tag. Ich versuche, Web-Service-Server mit yii und Client für Android zu erstellen. Hier meine WSDL, habe ich es auf meinem lokalen Rechner und die URL ist http://localhost:8888/places/index.php?r=Service/serviceSeife zwischen Yii und Android

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:ServiceControllerwsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" name="ServiceController" targetNamespace="urn:ServiceControllerwsdl"> 
<wsdl:message name="registrateRequest"> 
<wsdl:part name="login" type="xsd:string"/> 
<wsdl:part name="password" type="xsd:string"/> 
<wsdl:part name="email" type="xsd:string"/> 
<wsdl:part name="name" type="xsd:string"/> 
</wsdl:message> 
<wsdl:message name="registrateResponse"> 
<wsdl:part name="return" type="xsd:string"/> 
</wsdl:message> 
<wsdl:message name="authenticateRequest"> 
<wsdl:part name="login" type="xsd:string"/> 
<wsdl:part name="password" type="xsd:string"/> 
</wsdl:message> 
<wsdl:message name="authenticateResponse"/> 
<wsdl:portType name="ServiceControllerPortType"> 
<wsdl:operation name="registrate"> 
<wsdl:documentation/> 
<wsdl:input message="tns:registrateRequest"/> 
<wsdl:output message="tns:registrateResponse"/> 
</wsdl:operation> 
<wsdl:operation name="authenticate"> 
<wsdl:documentation/> 
<wsdl:input message="tns:authenticateRequest"/> 
<wsdl:output message="tns:authenticateResponse"/> 
</wsdl:operation> 
</wsdl:portType> 
<wsdl:binding name="ServiceControllerBinding" type="tns:ServiceControllerPortType"> 
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> 
<wsdl:operation name="registrate"> 
<soap:operation soapAction="urn:ServiceControllerwsdl#registrate" style="rpc"/> 
<wsdl:input> 
<soap:body use="encoded" namespace="urn:ServiceControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> 
</wsdl:input> 
<wsdl:output> 
<soap:body use="encoded" namespace="urn:ServiceControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> 
</wsdl:output> 
</wsdl:operation> 
<wsdl:operation name="authenticate"> 
<soap:operation soapAction="urn:ServiceControllerwsdl#authenticate" style="rpc"/> 
<wsdl:input> 
<soap:body use="encoded" namespace="urn:ServiceControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> 
</wsdl:input> 
<wsdl:output> 
<soap:body use="encoded" namespace="urn:ServiceControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> 
</wsdl:output> 
</wsdl:operation> 
</wsdl:binding> 
<wsdl:service name="ServiceControllerService"> 
<wsdl:port name="ServiceControllerPort" binding="tns:ServiceControllerBinding"> 
<soap:address location="http://localhost:8888/places/index.php?r=service/service&ws=1"/> 
</wsdl:port> 
</wsdl:service> 
</definitions> 

ich es mit dieser Klasse in yii erstellen

<?php 

class ServiceController extends CController 
{ 
    public function actions() 
    { 
     return array(
      'service'=>array(
       'class'=>'CWebServiceAction', 
      ), 
     ); 
    } 
    /** 
    * @param string login 
    * @param string password 
    * @param string email 
    * @param string name 
    * @return string 
    * @soap 
    */ 
    public function registrate($login, $password, $email, $name) 
    { 
     $user = new UserModel(); 
     /*create new user*/ 
     $user->login = $login; 
     $user->password = md5($password); 
     $user->email = $email; 
     $user->name = $name; 
     $user->active = 0; 
     //save to DB 
     $user->save(); 
     return 'success'; 

    } 
    /** 
    * @param string login 
    * @param string password 
    * return int 
    * @soap 
    */ 
    public function authenticate($login, $password) 
    { 
     $post=Post::model()->find('postID=:postID', array(':postID'=>10)); 
     $user = UserModel::model()->find('login:=login and password:=password', 
            array(':login' => $login, ':password'=>$password)); 
     if (!empty ($user)){ 
      return 1; 
     } 
     else{ 
      return 0; 
     } 

    } 
} 

Und wenn ich versuche, es auf Android whith zu verbinden ksoap

public class PlacesActivity extends Activity { 
    /** Called when the activity is first created. */ 
    private static String SOAP_ACTION = "urn:#registrate"; 
    private static String NAMESPACE = "urn:ServiceControllerwsdl"; 
    private static String METHOD_NAME = "registrate"; 
    private static String URL = "http://localhost:8888/places/index.php?r=Service/service"; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);  
      //Use this to add parameters 
      request.addProperty("login","nabiullin11"); 
      request.addProperty("password","qwer1234"); 
      request.addProperty("email","[email protected]"); 
      request.addProperty("name","nabiullin11"); 
      //Declare the version of the SOAP request 
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
      envelope.setOutputSoapObject(request); 
      //Needed to make the internet call 
      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
      try { 
       //this is the actual part that will call the webservice 
       androidHttpTransport.call(SOAP_ACTION, envelope); 
      } catch (Exception e) { 
       TextView t = (TextView)this.findViewById(R.id.resultbox); 
       //Get the first property and change the label text 
       t.setText("FAIL"); 
       e.printStackTrace(); 
      } 
      SoapObject result = (SoapObject)envelope.bodyIn; 
      if(result != null){ 
       TextView t = (TextView)this.findViewById(R.id.resultbox); 
       //Get the first property and change the label text 
       t.setText("SOAP response:\n\n" + result.getProperty(0).toString()); 
      } 

    } 

} 

Ich nehme immer Fail. Es gibt ein Problem meiner WSDL? oder habe ich solche Probleme Becous versuchen, eine Verbindung zu Localhost Server herzustellen?

+0

Ich habe versucht, auf Hosting-s zu posten erver part, nothing changed = ( – nabiullinas

+0

) Welche Stack-Trace hast du erhalten, als eine Exception eintrat? Welche Ausnahmemeldung wurde gewonnen? – asolovyov

Antwort

0

Das Problem in yii Rahmen ist, becouse es mir unnormal WSDL nimmt. Ich gemacht habe Sevice auf Java

+0

können Sie mir sagen, was ist das Problem in der WSDL meine Methoden funktionieren nicht ... ich kann nicht meine Methoden anrufen – Anand

0

Versuchen Sie, Ihre Parameter zu folgenden Änderungen:

private static String SOAP_ACTION = "urn:ServiceControllerwsdl#authenticate"; 
private static String NAMESPACE = "http://windwalk.ru"; 
private static String METHOD_NAME = "authenticate"; 
private static String URL = "http://windwalk.ru/places/index.php?r=service/service&ws=1"; 
1

mit diesem Parameter versuchen, im Umgang mit yii und Android und im das gleiche Problem in den letzten Tagen bekommen, und hier ist die Lösung:

static String SOAP_ACTION = "urn:ServiceControllerwsdl#authenticate"; 
private static String NAMESPACE = "urn:ServiceControllerwsdl"; 
private static String METHOD_NAME = "authenticate"; 
private static String URL = "http://localhost:8888/places/index.php?r=service/service&ws=1"; 
0

Vielleicht ist es ein wenig zu spät, aber wenn jemand für die richtige Antwort suchen wird, um die richtige params durch die wSDL-Datei gegeben verwenden, nicht die Programmiersprache ändern ..

YII WEBDIENST CONTROLLER

<?php class WebServiceController extends Controller{ 

public function actions() 
{ 
    return array(
     'quote'=>array(
      'class'=>'CWebServiceAction', 
     ), 
    ); 
} 


/** 
* @return string the joke 
* @soap 
*/ 
public function getJoke() 
{ 
    $jokes= array(0=>"Ordinarily, staring is creepy. But if you spread your attention across many individuals, then it's just people watching.", 
        1=>"A bear walks into a bar and says to the bartender, I'll have a pint of beer and a.......... packet of peanuts. The bartender asks, 'Why the big pause?'", 
        2=>"A man goes to a $10 hooker and contracts crabs. When he goes back to complain, the hooker laughs and says, What do you expect for $10 --lobster?" 
        ); 
    return $jokes[rand(0,2)]; 
}?> 

WSDL

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:WebServiceControllerwsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" name="WebServiceController" targetNamespace="urn:WebServiceControllerwsdl"> <wsdl:message name="getJokeIn"/> <wsdl:message name="getJokeOut"> <wsdl:part name="return" type="xsd:string"/> </wsdl:message> <wsdl:portType name="WebServiceControllerPortType"> <wsdl:operation name="getJoke"> <wsdl:documentation/> <wsdl:input message="tns:getJokeIn"/> <wsdl:output message="tns:getJokeOut"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="WebServiceControllerBinding" type="tns:WebServiceControllerPortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="getJoke"> <soap:operation soapAction="urn:WebServiceControllerwsdl#getJoke" style="rpc"/> <wsdl:input> <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:WebServiceControllerwsdl"/> </wsdl:input> <wsdl:output> <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:WebServiceControllerwsdl"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="WebServiceControllerService"> <wsdl:port name="WebServiceControllerPort" binding="tns:WebServiceControllerBinding"> <soap:address location="http://192.168.117.1/webservice_test/index.php?r=webservice/quote&ws=1"/> </wsdl:port> </wsdl:service> </definitions>

Konstanten mit ksoap2-android-Montage-2.5.2

package jvasconez.com.webservicetest; 

/** 
* Created by jvasconez on 8/4/2016. 
*/ 
import android.app.Activity; 
import android.os.AsyncTask; 
import android.widget.TextView; 

import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.transport.HttpTransportSE; 

public class WSManager extends AsyncTask<String,Integer,Boolean> { 

    public String response=""; 
    public Activity mActivity; 
    public WSManager(Activity act) 
    { 
     mActivity=act; 
    } 
    protected Boolean doInBackground(String... params) { 

     boolean result = true; 


     final String NAMESPACE = "urn:WebServiceControllerwsdl"; 
     final String URL="http://192.168.0.8/webservice_test/index.php?r=webservice/quote&ws=1"; 
     final String METHOD_NAME = "getJoke"; 
     final String SOAP_ACTION = "urn:WebServiceControllerwsdl#getJoke"; 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

     SoapSerializationEnvelope envelope = 
       new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.dotNet = false; 

     envelope.setOutputSoapObject(request); 

     HttpTransportSE transporte = new HttpTransportSE(URL,10000); 

     try 


    { 
      transporte.call(SOAP_ACTION, envelope); 

      response =(String) envelope.getResponse(); 
     } 
     catch (Exception e) 
     { 
      result = false; 
      response=""; 
     } 

     return result; 
    } 

    protected void onPostExecute(Boolean result) { 

     if (result) 
     { 
      TextView joke=(TextView)mActivity.findViewById(R.id.txt_joke); 
      joke.setText(response); 
     } 

    } 
} 

Und das ist es, es funktioniert gut ...

+0

Es ist nur ein Beispiel SOAP zwischen Android und PHP (mit Yii Framework) –