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
没有那个运气。不过谢谢。 –