PDA

View Full Version : مشکل به اتصال وب سرویس soap دات نت svc



ramin149
جمعه 03 بهمن 1393, 20:54 عصر
با سلام من با کد زیر می خوام اتصال بر قرار کنم به وب سرویس ولی نمی تونم لطفا کمک کنید و بگید مشکل کدم از کجاست

public class MainActivity extends ActionBarActivity {
private final String NAMESPACE = "http://tempuri.org/";
private final String URL = "http://89.165.51.133/WS/SvcReserveProWeb.svc";
private final String SOAP_ACTION = "http://tempuri.org/Search/";
private final String METHOD_NAME = "Search";
private String TAG = "PGGURU";
private static String celcius;
private static String fahren;
Button b;
TextView tv;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Celcius Edit Control
et = (EditText) findViewById(R.id.editText1);
//Fahrenheit Text control
tv = (TextView) findViewById(R.id.tv_result);
//Button to trigger web service invocation
b = (Button) findViewById(R.id.button1);
//Button Click Listener
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Check if Celcius text control is not empty
if (et.getText().length() != 0 && et.getText().toString() != "") {
//Get the text control value
celcius = et.getText().toString();
//Create instance for AsyncCallWS
AsyncCallWS task = new AsyncCallWS();
//Call execute
task.execute();
//If text control is empty
} else {
tv.setText("Please enter Celcius");
}
}
});
}

private class AsyncCallWS extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
Log.i(TAG, "doInBackground");
getFahrenheit(celcius);
return null;
}

@Override
protected void onPostExecute(Void result) {
Log.i(TAG, "onPostExecute");
tv.setText(fahren + "° F");
}

@Override
protected void onPreExecute() {
Log.i(TAG, "onPreExecute");
tv.setText("Calculating...");
}

@Override
protected void onProgressUpdate(Void... values) {
Log.i(TAG, "onProgressUpdate");
}

}
public void getFahrenheit(String celsius) {
//Create request
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//Property which holds input parameters
PropertyInfo celsiusPI = new PropertyInfo();
//Set Name
celsiusPI.setName("searchValue");
//Set Value
celsiusPI.setValue("اصفهان");
//Set dataType
celsiusPI.setType(String.class);
request.addProperty(celsiusPI);
PropertyInfo celsiusPI2 = new PropertyInfo();

//Set Name
celsiusPI2.setName("languageId");
//Set Value
celsiusPI2.setValue(1);
//Set dataType
celsiusPI2.setType(int.class);
//Add the property to request object
request.addProperty(celsiusPI2);
//Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
//Set output SOAP object
envelope.setOutputSoapObject(request);
//Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

try {
//Invole web service
androidHttpTransport.call(SOAP_ACTION, envelope);
//Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
//Assign it to fahren static variable
fahren =response.toString();

} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Celsius to Farenheit"
android:textSize="30dp" />

<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:numeric="integer"
android:singleLine="true" />

<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="Convert to Farenheit" />

<TextView
android:id="@+id/tv_result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="" android:textSize="26dp"/>

</LinearLayout>

sobhan1990
شنبه 04 بهمن 1393, 10:11 صبح
سلام
شماره پورت رو توی قسمت زیر اضاف کن و تست کن:


privatefinalString URL = "http://89.165.51.133:PORTNUMBER/WS/SvcReserveProWeb.svc";

ramin149
شنبه 04 بهمن 1393, 16:01 عصر
من url را هم با پورت تست کرم اما جواب نداد
private final String URL = "http://89.165.51.133:80/WS/SvcReserveProWeb.svc (http://89.165.51.133/WS/SvcReserveProWeb.svc)";