我正在使用货币转换器应用程序,我无法获得正确的输出(我得到零)。
我正在使用http://www.webservicex.net/ws/WSDetails.aspx?CATID=2&WSID=10中的网络服务。
WSDL将函数声明为:
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET/">
<s:element name="ConversionRate">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="FromCurrency" type="tns:Currency"/>
<s:element minOccurs="1" maxOccurs="1" name="ToCurrency" type="tns:Currency"/>
</s:sequence>
</s:complexType>
</s:element>
<s:simpleType name="Currency">
<s:restriction base="s:string">
<s:enumeration value="AFA"/>
<s:enumeration value="ALL"/>
<s:enumeration value="DZD"/>
<s:enumeration value="ARS"/>
<s:enumeration value="AWG"/>
<s:enumeration value="AUD"/>
</s:restriction>
</s:simpleType>
<s:element name="ConversionRateResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="ConversionRateResult" type="s:double"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="double" type="s:double"/>
</s:schema>
</wsdl:types>
我的Android课程:
public class MainActivity extends Activity {
private static final String NAMESPACE = "http://www.webserviceX.NET";
private static String URL = "http://www.webserviceX.NET/CurrencyConvertor.asmx?WSDL";
private static final String METHOD_NAME = "ConversionRate";
private static final String SOAP_ACTION = "http://www.webserviceX.NET/ConversionRate";
private TextView lblResult;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lblResult = (TextView) findViewById(R.id.result);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo propInfo=new PropertyInfo();
propInfo.name="FromCurrency";
propInfo.type=PropertyInfo.STRING_CLASS;
propInfo.setValue("AFA");
PropertyInfo propInfo2 = new PropertyInfo();
propInfo2.name="ToCurrency";
propInfo2.type = PropertyInfo.STRING_CLASS;
propInfo2.setValue("AUD");
request.addProperty(propInfo);
request.addProperty(propInfo2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet=true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope.getResponse();
lblResult.setText(resultsRequestSOAP.toString());
} catch (Exception e) {
lblResult.setText(e.getMessage());
}
}
有人对错误提出建议吗?
THX!
丹尼尔
答案 0 :(得分:1)
我认为你的网址字符串是:
private static String URL = "http://www.webserviceX.NET/CurrencyConvertor.asmx";
试试这个:
Object resultsRequestSOAP = envelope.getResponse();
而不是:
SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope.getResponse();
答案 1 :(得分:0)
您的服务说明显示命名空间为http://www.webserviceX.NET/
尝试添加额外的/