0
我正在使用SOAP與寫在.Net
中的Webservice進行通信。源代碼如下:當我嘗試調用Web服務時出現KSoap錯誤消息
public class SlipperyAsSoap extends Activity {
Button sendMsg;
TextView resultText;
EditText query;
final String NAMESPACE = "http://tempuri.org/";
final String SOAP_ACTION = "http://tempuri.org/IIOService/SendMessage";
final String METHOD_NAME = "SupportedMessageTypes";
final String URL = "http://biovnap.no.netserver/Bio/IOService.svc?wsdl";
// private static String SOAP_ACTION1 =
// "http://tempuri.org/FahrenheitToCelsius";
// private static String SOAP_ACTION2 =
// "http://tempuri.org/CelsiusToFahrenheit";
// private static String NAMESPACE = "http://tempuri.org/";
// private static String METHOD_NAME1 = "FahrenheitToCelsius";
// private static String METHOD_NAME2 = "CelsiusToFahrenheit";
// private static String URL =
// "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
sendMsg = (Button) findViewById(R.id.button1);
resultText = (TextView) findViewById(R.id.textView1);
query = (EditText) findViewById(R.id.editText1);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
sendMsg.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// Use this to add parameters
// request.addProperty("Fahrenheit",
// query.getText().toString());
// Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(
URL);
androidHttpTransport.debug = true;
// this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject) envelope.bodyIn;
if (result != null) {
// Get the first property and change the label text
resultText.setText(result.getProperty(0).toString());
} else {
Toast.makeText(getApplicationContext(), "No Response",
Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
Log.e("XMLPullParser: ", e.getMessage());
}
}
});
}
}
正如您所看到的,我嘗試聯繫W3Schools的Web服務,僅用於測試目的。而這個完美的作品,但是當我嘗試聯繫我的web服務,這是在同一個網絡我的手機在到達,我只得到了logcat的這個錯誤:
10-11 10:11:21.435: E/XMLPullParser:(1043): unexpected type (position:END_DOCUMENT [email protected]:1 in [email protected])
我試圖達到的方法是這樣的一種:
wsdl:operation name="SupportedMessageTypes">
<wsdl:input wsaw:Action="http://tempuri.org/IIOService/SupportedMessageTypes" message="tns:IIOService_SupportedMessageTypes_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IIOService/SupportedMessageTypesResponse" message="tns:IIOService_SupportedMessageTypes_OutputMessage"/>
</wsdl:operation>
這個錯誤,當我嘗試做一個androidHttpTransport.call(SOAP_ACTION, envelope);
我知道,這應該被放在一個的AsyncTask,每個網絡運營應當建立這樣一來,所以請不要抱怨發生。
這裏是WCF測試客戶端
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1">http://tempuri.org/IIOService/SupportedMessageTypes</a:Action>
<a:MessageID>urn:uuid:5c3f721a-f0d6-4be9-9699-10b48a2ee146</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
</s:Header>
<s:Body>
<SupportedMessageTypes xmlns="http://tempuri.org/" />
</s:Body>
</s:Envelope>
請求XML和響應XML
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://tempuri.org/IIOService/SupportedMessageTypesResponse</a:Action>
<a:RelatesTo>urn:uuid:85436e79-86bb-4370-843c-b1047975b864</a:RelatesTo>
</s:Header>
<s:Body>
<SupportedMessageTypesResponse xmlns="http://tempuri.org/">
<SupportedMessageTypesResult xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<b:string>EurodacTestReplyGenerator</b:string>
<b:string>EurodacBlock</b:string>
</SupportedMessageTypesResult>
</SupportedMessageTypesResponse>
</s:Body>
</s:Envelope>
任何人都可以給我這個錯誤消息的提示?
在此先感謝!
感謝您的答案,但我不斷收到問題中所述的錯誤信息。在XML頭中,命名空間是這樣聲明的:'targetNamespace =「http://tempuri.org/」>'SupportedMessageTypes是這樣聲明的:' wsdl:output> wsdl:operation>' –
我不確定,但也許你可以在我的答案中嘗試更新的SOAP_ACTION。實際上,我自己並沒有在嵌套目錄上工作。 – Swayam
沒有那個運氣。不過謝謝。 –