我有这样的SOAP请求,它运行正常:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://com/">
<soapenv:Header/>
<soapenv:Body>
<web:ConversionRate>
<!--Optional:-->
<FromCurrency>?</FromCurrency>
<!--Optional:-->
<ToCurrency>?</ToCurrency>
</web:ConversionRate>
</soapenv:Body>
</soapenv:Envelope>
我正在改变请求,以理解这些概念:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<soapenv:Header/>
<soapenv:Body>
<ConversionRate xmlns="http://com/">>
<!--Optional:-->
<FromCurrency>?</FromCurrency>
<!--Optional:-->
<ToCurrency>?</ToCurrency>
</ConversionRate>
</soapenv:Body>
</soapenv:Envelope>
第二个没有用,给出了错误的答案。
我的服务类是
package com;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
@WebService (targetNamespace="http://com/")
public class CurrencyConvertor
{
public String ConversionRate (@WebParam(name = "FromCurrency") String FromCurrency, @WebParam(name = "ToCurrency") String ToCurrency)
{
System.out.println("ST\n" + FromCurrency + "\n" + ToCurrency + "\nEnd" );
switch(FromCurrency+","+ToCurrency)
{
case "USD,INR":
return "58";
case "INR,USD":
return "0.017";
default:
return "XXX";
}
}
}
第二个请求总是属于默认情况,事实是,由于我更改了名称空间,因此值发送为null。所以我的Web服务应该正确回答第二个请求,应该导致什么问题,如何纠正这个问题。
答案 0 :(得分:0)
你的命名空间不正确,即使它看起来很好。 我必须将com更改为com.example,因为无法使用仅限com的链接发布回答。
tns = http://com.example/定义于 WebService,而不是webmethod。将方法声明更改为
public String ConversionRate (
@WebParam(name = "FromCurrency", tagetNamespace = "http://com.example/") String FromCurrency,
@WebParam(name = "ToCurrency", tagetNamespace = "http://com.example/") String ToCurrency) {
...
}
即使我不确定XML是否具有有效格式
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<soapenv:Header/>
<soapenv:Body>
<ConversionRate xmlns="http://com.example/">
<FromCurrency>?</FromCurrency>
<ToCurrency>?</ToCurrency>
</ConversionRate>
</soapenv:Body>
</soapenv:Envelope>
仅为参数需要或命名空间
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<soapenv:Header/>
<soapenv:Body>
<ConversionRate>
<FromCurrency xmlns="http://com.example/">?</FromCurrency>
<ToCurrency xmlns="http://com.example/">?</ToCurrency>
</ConversionRate>
</soapenv:Body>
</soapenv:Envelope>