1. Phenomenon
Integrating the web service of Spring + CXF, the WSDL is successfully published, but an error is reported when calling
org.apache.cxf.common.i18n.uncheckedexception: no operation was found with
2. Solution 1
: add targetNamespace in the service interface
package com.gblfy.service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService(targetNamespace = "http://impl.service.gblfy.com/")
public interface IUserService {
@WebMethod
public String getCxf(@WebParam(name = "reqXml") String reqXml);
}
Implementation class
package com.gblfy.service.impl;
import com.gblfy.service.IUserService;
import javax.jws.WebService;
@WebService
public class UserServiceImpl implements IUserService {
@Override
public String getCxf(String reqXml) {
System.out.println("Message received:" + reqXml);
return "OK";
}
}
client
/**
* Single/multi-parameter calling tool class (Object type)
*
* @param cxfUrl url address
* @param method call method name
* @param reqXml send message body
* @return res return result
* @throws Exception If there is an exception, output the exception on the console and throw the exception
*/
public static String cxfClientParam(String cxfUrl, String method, Object... reqXml) throws Exception {
String res = null;
// Create a dynamic client
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(cxfUrl);
// If you need a password, you need to add a user name and password
// client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME, PASS_WORD));
Object[] objects = new Object[0];
try {
// Basic format: invoke("method name", parameter 1, parameter 2, parameter 3....);
objects = client.invoke(method, reqXml);
res = objects[0].toString();
System.out.println("Return data:" + res);
} catch (java.lang.Exception e) {
e.printStackTrace();
throw e;
}
return res;
}
3. Solution 2
Use QName and add the address of the service interface
package com.gblfy.service.client;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.stereotype.Component;
import javax.xml.namespace.QName;
/**
* cxf client call (packaged inside the enterprise)
*
* @author gblfy
* @date 2021-09-17
*/
@Component
public class CxfClient {
public static void main(String[] args) throws Exception {
String cxfUrl = "http://127.0.0.1:8080/spring_cxf_war/webservice/userWS?wsdl";
String method = "getCxf";
String reqXml = "cxf request message";
//Call the service
CxfClient.cxfClientParam(cxfUrl, method, reqXml);
}
/**
* Single/multi-parameter calling tool class (Object type)
*
* @param cxfUrl url address
* @param method call method name
* @param reqXml send message body
* @return res return result
* @throws Exception If there is an exception, output the exception on the console and throw the exception
*/
public static String cxfClientParam(String cxfUrl, String method, String reqXml) throws Exception {
String res = null;
// Create a dynamic client
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(cxfUrl);
// If you need a password, you need to add a user name and password
// client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME, PASS_WORD));
Object[] objects = new Object[0];
try {
// Basic format: invoke("method name", parameter 1, parameter 2, parameter 3....);
QName qName = new QName("http://impl.service.gblfy.com/",method);
objects = client.invoke(qName, reqXml);
res = objects[0].toString();
System.out.println("Return data:" + res);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return res;
}
}
Read More:
- [Solved] CXF Call webservice Client Error: 2 counts of InaccessibleWSDLException
- [Solved] webService Error: webservice Interface call error reported.
- [Solved] FileUploadException: the request was rejected because no multipart boundary was found
- [Solved] SAX2 driver class org.apache.xerces.parsers.SAXParser not found
- [Solved] Caused by: java.lang.ClassNotFoundException: org.apache.flink.api.common.typeinfo.TypeInformation
- [Elasticsearch Exception]Found interface org.elasticsearch.common.bytes.BytesReference
- [Solved] java.lang.noclassdeffounderror when idea runs Flink: org/Apache/flick/API/common/executionconfig
- [Solved] flink Write Files Error: lang.NoClassDefFoundError: org/apache/flink/api/common/typeinfo/TypeInformation
- Kafka executes the script to create topic error: error org apache. kafka. common. errors. InvalidReplicationFactorException: Replicati
- [Solved] NTP Sync common error: no server suitable for synchrnization found
- How to Solve org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) Error
- [Solved] Latex&VScode Error: I found no bibdata command//command//citation—while reading file*.aux
- Error: Unable to build IHost No DbContext named ‘PersistedGrantDbContext‘ was found.
- [Solved] MSP430F5529 Error initializing emulator:No USB FET was found
- [Solved] eclipse Error: org.apache.hadoop.hbase.NotServingRegionException:
- [Solved] Springboot Error: org.apache.catalina.core.ContainerBase : A child container failed during start
- [Solved] ERROR SparkContext: Error initializing SparkContext. org.apache.spark.SparkException: Could not pars
- mybatis-plus calls its own selectById method and reports an error: org.apache.ibatis.binding.BindingException:
- [Solved] Mybatis:Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.
- Gradle Package Project Lombok Not Working: No serializer found for class com.qbb.User and no properties discovered to create BeanSerializer……