我正在尝试公开 SOAP Web 服务。为此,我使用的是 apache camel。所以我必须使用 apache CXF 来公开 SOAP Web 服务。但我得到了错误。
org.xml.sax.SAXParseException;行号:2;列号:223;属性“prefix="xmlns",localpart="tns",rawname="xmlns:tns"" 的值无效。带前缀的命名空间绑定不能为空。
这是我编写的代码。
@WebService(endpointInterface="com.ericsson.fdp.SOAP.FulfillmentService", targetNamespace = "http://apache.org/hello_world_soap_http",portName="FulfillmentServicePort",serviceName="FulfillmentService")
public class FulfillmentServiceImpl implements FulfillmentService{
@Produce(uri = "servlet:///fulfillmentService?servletName=FulfillmentService&matchOnUriPrefix=false")
private ProducerTemplate template;
@Override
public FulfillmentResponse buyProduct(String input, String userName, String password, String msisdn, String iname) {
Map<String,Object> queryMap = new HashMap<>();
queryMap.put("input", input);
queryMap.put("password", password);
queryMap.put("msisdn", msisdn);
queryMap.put("iname", iname);
String response = (String) template.requestBodyAndHeaders(null, queryMap);
FulfillmentResponse responseObject=null;
try {
responseObject = XmlUtil.unmarshall(response, FulfillmentResponse.class);
} catch (JAXBException e) {
e.printStackTrace();
}
return responseObject;
}
}
这是上述实现的接口
@WebService(name="fulfillmentService", targetNamespace = "http://apache.org/hello_world_soap_http",portName="FulfillmentServicePort",serviceName="FulfillmentService")
public interface FulfillmentService {
public FulfillmentResponse buyProduct(String input,String userName, String password,String msisdn,String iname);
}
我试图检查。这是为上述代码创建的 WSDL。
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="fulfillmentService" targetNamespace="" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://apache.org/hello_world_soap_http" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:import namespace="http://apache.org/hello_world_soap_http" location="fulfillmentService.wsdl">
</wsdl:import>
<wsdl:binding name="fulfillmentServiceSoapBinding" type="ns1:fulfillmentService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="buyProduct">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="buyProduct">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="buyProductResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="fulfillmentService">
<wsdl:port name="fulfillmentServicePort" binding="fulfillmentServiceSoapBinding">
<soap:address location="http://127.0.0.1:8980/cisBusiness/services/fulFillment"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
我该如何解决这个错误?