gpt4 book ai didi

java - Weblogic 12c 上的 JAX-WS 网络服务

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:12:03 24 4
gpt4 key购买 nike

我正在通过以下链接发布网络服务。

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/

此代码在部署在 Tomcat 上时有效。但它在 weblogic 12c 中不起作用。我需要提供额外的参数吗?部署过程中我没有异常。我在部署的应用程序下的 Web 服务部分看不到任何项目 weblogic 控制台。

更新:部署madhava编码的webservicetest.war后

enter image description here

最佳答案

我已经创建了自己的应用程序来检查您的问题。确实它对我来说很好用。我与您分享相同的内容。

1) 创建一个简单的web应用程序。(在Eclipse File+New+Dynamic Web Project中)

2) 创建一个接口(interface)作为网络服务。

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) 创建一个实现您编写的网络服务的类。

    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)创建一个保留名称、端口名称、服务名称等的类

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) 创建应用程序的 war 文件并将其部署到 weblogic 服务器中。在这里您将能够看到 Web 服务为“CalculatorServiceService”

CalculatorService

在 weblogic 中测试客户端的 URL:

http://localhost:7001/wls_utc/?wsdlUrl=http%3A%2F%2Flocalhost%3A7001%2FWebServicesTest%2FCalculatorServiceService%3FWSDL

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));

}

}

希望对你有帮助!

关于java - Weblogic 12c 上的 JAX-WS 网络服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26507355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com