简体   繁体   English

无法使用kso​​ap2库调用Soap Web服务

[英]Unable to call soap web service using ksoap2 library

I am new to android and very new to soap web service calling. 我是android的新手,并且是soap网络服务调用的新手。 I am trying to call soap based web service using ksoap2 library but continuously getting error message 我正在尝试使用kso​​ap2库调用基于soap的Web服务,但不断收到错误消息

java.io.IOException: HTTP request failed, HTTP status: 405 java.io.IOException:HTTP请求失败,HTTP状态:405

But I am not able to understand why is it happening. 但是我不明白为什么会这样。 I have searched over internet and could not found any solution to my problem. 我已经通过互联网搜索,找不到解决我问题的方法。

these are the fields I am using: 这些是我正在使用的字段:

private static final String METHOD_NAME = "Authenticate";
private static final String SOAP_ACTION = "http://tempuri.org/IService1/Authenticate";
private static final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
private static final String NAMESPACE = "http://tempuri.org/";

This is the wsdl url: http://www.w3schools.com/webservices/tempconvert.asmx?WSDL 这是wsdl网址: http : //www.w3schools.com/webservices/tempconvert.asmx? WSDL

This should be the request format: http://www.w3schools.com/webservices/tempconvert.asmx?WSDL 这应该是请求格式: http : //www.w3schools.com/webservices/tempconvert.asmx?WSDL

I have tested this service with web service studio and got the following request and working fine. 我已经在Web Service Studio中测试了此服务,并得到以下请求并且工作正常。

<?xml version="1.0" encoding="utf-16"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><Authenticate xmlns="http://tempuri.org/">
  <UserName>test</UserName>
  <Password>test</Password>
</Authenticate></soap:Body></soap:Envelope>

I am trying to call this service using below code 我正在尝试使用以下代码调用此服务

request = new SoapObject(NAMESPACE, METHOD_NAME);       
request.addProperty("UserName","test");
request.addProperty("Password","test");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
envelope.setOutputSoapObject(request);

HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(SOAP_ACTION, envelope);

So please help me to get response from this service. 因此,请帮助我获得此服务的回复。

Why are you using "http://demo.knowcross.com/TritonMobileService"; 为什么使用"http://demo.knowcross.com/TritonMobileService"; as URL ? 作为URL Service address you can find in wsdl and it is: 您可以在wsdl中找到的服务地址为:

<soap:address location="http://demo.knowcross.com/TritonMobileService/Service1.svc"/>

so you should use it as URL . 因此您应该将其用作URL

EDIT: You can set ht.debug=true and check whether ht.requestDump is correct. 编辑:您可以设置ht.debug=true并检查ht.requestDump是否正确。 First of all you should add the namespace for properties like this: 首先,您应该为以下属性添加名称空间:

PropertyInfo p = new PropertyInfo();
p.setNamespace(NAMESPACE);
p.setValue("test");
p.setName("UserName");
request.addProperty(p);
p = new PropertyInfo();
p.setNamespace(NAMESPACE);
p.setValue("test");
p.setName("Password");
request.addProperty(p);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM