我有以下WCF webservice消費通過KSOAP2 Android上的WCF服務給錯誤
我想使用它在android系統client.My代碼到目前爲止是
public class SOAP_TestActivity extends Activity {
private final String NAMESPACE = "http://tempuri.org/";
private final String URL = "http://50.19.226.15/Office365Admin/MsOnline.svc";
private final String SOAP_ACTION = "http://tempuri.org/IMsOnline/ValidateUser";
private final String METHOD_NAME = "ValidateUser";
private final String user_id= "[email protected]";
private final String password= "[email protected]";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button signin = (Button) findViewById(R.id.regsubmitbtn);
signin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
boolean auth=doLogin();
System.out.println(auth);
Toast.makeText(getApplicationContext(), String.valueOf(auth), Toast.LENGTH_SHORT).show();
}
});
}
private boolean doLogin() {
boolean result=false;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("userid", user_id);
request.addProperty("password",password);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
Log.d("myApp", request.toString());
System.out.println(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive soapPrimitiveResults = (SoapPrimitive)envelope.getResponse();
Log.d("myApp", soapPrimitiveResults.toString());
System.out.println("myApp" +soapPrimitiveResults);
if(soapPrimitiveResults.toString().equalsIgnoreCase("true"))
{
result = true;
}
}catch(SocketException ex)
{
Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage());
ex.printStackTrace();
}
catch (Exception e) {
Log.e("Error : " , "Error on soapPrimitiveData() " + e.getMessage());
e.printStackTrace();
}
return result;
}
}
此代碼的工作沒有任何異常,但我我無法登錄到我的應用程序,因爲方法ValidateUser
總是返回false.This相同的Web服務已在Windows Phone中使用,並且沒有任何問題。而且用戶名和密碼是100%正確的。
看起來在NAMESPACE
和SOAP_ACTION
中存在一些問題。我已經經歷了一些教程走了,他們說,SOAP_ACTION
通過連接NAMESPACE
與METHOD_NAME
。所以,如果我按照教程我SOAP_ACTION
應該
"http://tempuri.org/ValidateUser"
製作,但在WSDL link
的方法"ValidateUser"
給出的SOAP_ACTION
是
"http://tempuri.org/IMsOnline/ValidateUser"
。
我是新來的WCF Webservices和SOAP.Can任何人請告訴我如何實現WSDL Document(link is at the top)
中給出的方法。 看起來像缺少重要的東西,但不知道是什麼。