1

我有一个这样的 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 服务应该正确回答第二个请求,应该是什么导致问题,如何纠正这个问题。

4

1 回答 1

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>
于 2013-06-19T05:53:42.690 回答