Friday, February 28, 2014

ksoap2 call WCF interfaces Tip Cannot serialize: 11.0


I am learning to develop Andriod program, we encounter a very depressed, I was in the top of the server-side WCF service implements a simple addition, subtraction four functions, parameters are two double type data. For example, I would like to achieve 11 + 12 =? But when the client calls the phone always throws an exception,

e RuntimeException (id = 830082723416)
cause RuntimeException (id = 830082723416)
detailMessage "Cannot serialize: 11.0" (id = 830082724304)
stackState (id = 830082724336)
stackTrace null
Server-side code is as follows:
 
public class Demo: Interface
{

# Region Interface Members

public double Add (double a, double b)
{
return a + b;
}

public double subtract (double a, double b)
{
return a - b;
}

public double Multiply (double a, double b)
{
return a * b;
}

public double Divide (double a, double b)
{
if (b == 0)
return 0;
else return a / b;
}

# Endregion
}

Interface:
 
[ServiceContract]
public interface Interface
{
[OperationContract]
double Add (double a, double b);
[OperationContract]
double subtract (double a, double b);
[OperationContract]
double Multiply (double a, double b);
[OperationContract]
double Divide (double a, double b);
}


This is the complete code for the client:
 
public class Android_WCF_CalculateActivity extends Activity {

private static final String [] m_Operators = {"+", "-", "*", "/"};
private static final String m_Namespace = "http://tempuri.org/";
private static final String m_URL = "http://192.168.1.97:8000/Post/Service/Demo";
private static final String m_Soap = "http://tempuri.org/Interface/";

private TextView m_TextA, m_TextB, m_TextResult;
private Spinner m_SpOperators;
private Button m_BtnOK, m_BtnCancel;

private ArrayAdapter adapter;

/ ** Called when the activity is first created. * /
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);

Init ();
}

private void Init () {
m_TextA = (TextView) this.findViewById (R.id.editText1);
m_TextB = (TextView) this.findViewById (R.id.editText2);
m_TextResult = (TextView) this.findViewById (R.id.editText3);
m_SpOperators = (Spinner) this.findViewById (R.id.spinner1);
m_BtnOK = (Button) this.findViewById (R.id.button2);
m_BtnCancel = (Button) this.findViewById (R.id.button1);

adapter = new ArrayAdapter (this, android.R.layout.simple_spinner_item,
m_Operators);
adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item);
m_SpOperators.setAdapter (adapter);

BtnOK_Click ();
BtnCancel_Click ();
}

private void BtnOK_Click () {
m_BtnOK.setOnClickListener (new OnClickListener () {
public void onClick (View v) {
String methodName;
String item = m_SpOperators.getSelectedItem () toString ();.
if ("+" == item)
methodName = "Add";
else if ("-" == item)
methodName = "subtract";
else if ("*" == item)
methodName = "Multiply";
else
methodName = "Divide";
double value1 = Double.parseDouble (m_TextA.getText () toString ().);
double value2 = Double.parseDouble (m_TextB.getText () toString ().);
SoapObject requet = new SoapObject (m_Namespace, methodName);
requet.addProperty ("a", value1);
requet.addProperty ("b", value2);

SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope (SoapEnvelope.VER11);
envelope.bodyOut = requet;
envelope.dotNet = true;
HttpTransportSE transport = new HttpTransportSE (m_URL);
transport.debug = true;
try {
transport.call (m_Soap + methodName, envelope);
SoapObject response = (SoapObject) envelope.bodyIn;
m_TextResult.setText (response.toString ());
} Catch (Exception e) {
e.printStackTrace ();
}
}
});
}

private void BtnCancel_Click () {
m_BtnCancel.setOnClickListener (new OnClickListener () {
public void onClick (View v) {
Android_WCF_CalculateActivity.this.finish ();
}
});
}
}


This is the WSDL file:
 



< br />























































































http://192.168.1.97:8000/Post/Service/Demo




The above is a complete code, I hope to help find out why. .<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Answered. . . . Their top
Reply:
. . Halo nobody. . Today, the last one. . Saying, moderators save Jia
Reply:
I advise you a ah, you are now the best way is to rewrite the server-side code string into the receiver, and then cast. ksoap ills, can not transmit double type, those who know, please tell me, I want to know for a long time, and once I program encountered this situation, we must do a lot of trouble.
Reply:
I advise you a ah, you are now the best way is to rewrite the server-side code string into the receiver, and then cast. ksoap ills, can not transmit double type, those who know, please tell me, I want to know for a long time, and once I program encountered this situation, we must do a lot of trouble.
Reply:
Thank you, I'll try that too pulled. .
Reply:
The reply was deleted at the moderator 2012-04-16 16:44:00

Reply:
Too thank the 3rd floor, the problem is solved
Reply:
Why do I call transport.call () always being given it
Reply:
No problem with java main function test, put android Underneath there is a problem
Reply:
Code does
Reply:
reference to the 7th floor a175059525 reply:
too thank the 3rd floor, the problem is solved
ask how to solve? Seeking to share, I have encountered this problem
Reply:
I'm not the type of transmission line LIST, the landlord how to solve

No comments:

Post a Comment