java Weblogic 12c 上的 JAX-WS Web 服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26507355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JAX-WS webservice on Weblogic 12c
提问by Ahmet Karakaya
I am following links below to publish a webservice.
我正在按照下面的链接发布网络服务。
http://www.mkyong.com/webservices/jax-ws/jax-ws-java-web-application-integration-example/http://stlarch.blogspot.com.tr/2013/02/building-jax-ws-webservices-in-weblogic.htmlhttp://www.mkyong.com/webservices/jax-ws/jax-ws-spring-integration-example/http://examples.javacodegeeks.com/enterprise-java/jws/jax-ws-spring-integration-example/
http://www.mkyong.com/webservices/jax-ws/jax-ws-java-web-application-integration-example/ http://stlarch.blogspot.com.tr/2013/02/building-jax- ws-webservices-in-weblogic.html http://www.mkyong.com/webservices/jax-ws/jax-ws-spring-integration-example/ http://examples.javacodegeeks.com/enterprise-java/jws /jax-ws-spring-integration-example/
This code works when deployed on Tomcat. But it does not work at weblogic 12c. Do I need to give additional parameters? I am not having an exception while deploy process. I cannnot see any item one weblogic console at Webservices section under deployed application.
此代码在部署在 Tomcat 上时有效。但它不适用于 weblogic 12c。我需要提供额外的参数吗?我在部署过程中没有异常。我在部署的应用程序下的 Webservices 部分看不到任何一项 weblogic 控制台。
UPDATE: After deploying webservicetest.war coded by madhava
更新:部署由 madhava 编码的 webservicetest.war 后
采纳答案by Ahmet Karakaya
I have read the following link then applied the servlet
mapping technique.
I can access the wsdl
and make successfuly SOAP
request via SOAPUI
我已阅读以下链接,然后应用了servlet
映射技术。我可以访问wsdl
并successfulySOAP
通过请求SOAPUI
http://www.krestjaninoff.ru/2013/09/custom-context-path-for-jax-ws-web.html
http://www.krestjaninoff.ru/2013/09/custom-context-path-for-jax-ws-web.html
<servlet>
<servlet-name>TestWSPort</servlet-name>
<display-name>TestWSPort</display-name>
<servlet-class>name.krestjaninoff.TestWSService</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestWSPort</servlet-name>
<url-pattern>myOwn/path/TestWS</url-pattern>
</servlet-mapping>
Here is the project I have created, you can download https://www.dropbox.com/s/vztkfqxekw43n4a/WeblogicJaxWsProject.zip?dl=0
这里是我创建的项目,可以下载 https://www.dropbox.com/s/vztkfqxekw43n4a/WeblogicJaxWsProject.zip?dl=0
Thanks Mikhail Krestjaninoff who is owner of the post given by link above
感谢 Mikhail Krestjaninoff,他是上面链接中帖子的所有者
回答by Unknown
I Have created my own application to check your issue. Indeed it is working fine for me. I am sharing the same with you.
我已经创建了自己的应用程序来检查您的问题。事实上,它对我来说很好用。我和你分享同样的东西。
1) Create a simple web application.(In Eclipse File+New+Dynamic Web Project)
1) 创建一个简单的web应用程序。(在Eclipse File+New+Dynamic Web Project中)
2) Create an interface as a webservice.
2)创建一个接口作为网络服务。
package com.madhava.service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import com.madhava.CalculatorServiceConstant;
@WebService(name = CalculatorServiceConstant.Name.CALCULATOR_SERVICE, targetNamespace = CalculatorServiceConstant.CALCULATOR_SERVICE_TARGET_NAME_SPACE)
public interface CalculatorService {
@WebMethod
@WebResult(name="sum")Integer addNumber(@WebParam(name = "number1") Integer number1,
@WebParam(name = "number2") Integer number2);
@WebMethod
@WebResult(name="difference")Integer subtractNumber(@WebParam(name = "number1") Integer number1,
@WebParam(name = "number2") Integer number2);
@WebMethod
@WebResult(name="multiplication")Long multiplyNumber(@WebParam(name = "number1") Integer number1,
@WebParam(name = "number2") Integer number2);
@WebMethod
@WebResult(name="division")Double divideNumber(@WebParam(name = "number1") Integer number1,
@WebParam(name = "number2") Integer number2);
}
3) Create a class which implements the webservice which you have written.
3) 创建一个实现您编写的 web 服务的类。
import javax.ejb.Stateless;
import javax.jws.WebService;
import com.madhava.service.CalculatorService;
@Stateless
@WebService(portName = CalculatorServiceConstant.PortName.CALCULATOR_SERVICE, serviceName = CalculatorServiceConstant.ServiceName.CALCULATOR_SERVICE, endpointInterface = CalculatorServiceConstant.EndPointInterface.CALCULATOR_SERVICE, targetNamespace = CalculatorServiceConstant.CALCULATOR_SERVICE_TARGET_NAME_SPACE)
public class CalculatorServiceImpl implements CalculatorService {
@Override
public Integer addNumber(Integer number1, Integer number2) {
if (number1 != null && number2 != null) {
return number1 + number2;
} else {
return 0;
}
}
@Override
public Integer subtractNumber(Integer number1, Integer number2) {
if (number1 != null && number2 != null) {
if (number1 > number2) {
return number1 - number2;
} else {
return number2 - number1;
}
} else {
return 0;
}
}
@Override
public Long multiplyNumber(Integer number1, Integer number2) {
if (number1 != null && number2 != null) {
return (long) (number1 * number2);
} else {
return 0L;
}
}
@Override
public Double divideNumber(Integer number1, Integer number2) {
if ((number1 != null && number2 != null) || number2!=0) {
return (double) (number1 / number2);
}
else {
return 0.0D;
}
}
}
4)Create a Class which keeps the name, portname, service name etc.
4)创建一个保留名称,端口名,服务名称等的类。
public class CalculatorServiceConstant {
public static final String CALCULATOR_SERVICE_TARGET_NAME_SPACE = "http://calculatorservices.madhava.com";
private CalculatorServiceConstant() {
}
public static class Name {
public static final String CALCULATOR_SERVICE = "CalculatorService";
// Private Constructor
private Name() {
}
}
public static class PortName {
public static final String CALCULATOR_SERVICE = "CalculatorServicePort";
// Private Constructor
private PortName() {
}
}
public static class ServiceName {
public static final String CALCULATOR_SERVICE = "CalculatorServiceService";
// Private Constructor
private ServiceName() {
}
}
public static class EndPointInterface {
public static final String CALCULATOR_SERVICE = "com.madhava.service.CalculatorService";
// Private Constructor
private EndPointInterface() {
}
}
public static class JNDI {
public static final String CALCULATOR_SERVICE = "CalculatorService#com.madhava.service.CalculatorService";
// Private Constructor
private JNDI() {
}
}
}
5)Create a war file of the application and deploy the same in weblogic server. Here you will be able to see the webservice as 'CalculatorServiceService'
5) 创建应用程序的war 文件并将其部署在weblogic 服务器中。在这里,您将能够看到网络服务为“CalculatorServiceService”
Url to test client in weblogic:
在 weblogic 中测试客户端的 URL:
http://localhost:7001/wls_utc/?wsdlUrl=http%3A%2F%2Flocalhost%3A7001%2FWebServicesTest%2FCalculatorServiceService%3FWSDL
6)Finally to check whether it is working properly or not I have created the client class.
6)最后检查它是否正常工作我已经创建了客户端类。
package com.madhava.client;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import com.madhava.CalculatorServiceConstant;
import com.madhava.service.CalculatorService;
public class CalculatorServiceClient {
/**
* @param args
* @throws MalformedURLException
*/
public static void main(String[] args) throws MalformedURLException {
URL url = new URL("http://localhost:7001/WebServicesTest/CalculatorServiceService?wsdl");
QName qname = new QName(CalculatorServiceConstant.CALCULATOR_SERVICE_TARGET_NAME_SPACE, CalculatorServiceConstant.ServiceName.CALCULATOR_SERVICE);
Service service = Service.create(url, qname);
CalculatorService calculatorService = service.getPort(CalculatorService.class);
System.out.println(calculatorService.addNumber(10,20));
}
}
Hope it helps you !
希望对你有帮助!