1.Open NetBeans 8.0.2
2.File->New Project->Java Web->Web Application
3.Project Name -> myprac
4.Next (ensure glass fish selected)
5.right click on myprac->new->web service
name: ImageWS
package: mypkg

cpy past ImageWS code into this ImageWS file

ImageWS code below:

package mypkg;

import java.io.*;
import javax.jws.Oneway;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.xml.ws.soap.MTOM;

@MTOM(enabled = true, threshold = 60000)
@WebService(serviceName = "ImageWS")
public class ImageWS {

    @WebMethod(operationName = "upload")
    @Oneway
    public void upload(@WebParam(name = "Filename") String Filename, @WebParam(name = "ImageBytes") byte[] ImageBytes) {
        String filePath = "C:/Picture/upload/" + Filename;
        try {
            FileOutputStream fos = new FileOutputStream(filePath);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            bos.write(ImageBytes);
            bos.close();
            System.out.println("Received file: " + filePath);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @WebMethod(operationName = "download")
    public byte[] download(@WebParam(name = "Filename") String Filename) {
        String filePath = "C:/Picture/upload/" + Filename;
        System.out.println("Sending file: " + filePath);
        try {
            File file = new File(filePath);
            FileInputStream fis = new FileInputStream(file);
            BufferedInputStream bis = new BufferedInputStream(fis);
            byte[] fileBytes = new byte[(int) file.length()];
            bis.read(fileBytes);
            bis.close();
            return fileBytes;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }
}


##end code

then run app using green play button
it should open web browser on localhost

6.right click on myprac->new->Web Service Client
Browse and select ImageWS in it
set package: pkg

expand web pages and delete older index.html
right click on myprac->new->JSP
file name: index

paste index code in this file

<%@page import="java.io.BufferedOutputStream"%>
<%@page import="java.io.FileOutputStream"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.BufferedInputStream"%>
<%@page import="java.io.File"%>
<%@page import="javax.xml.ws.soap.MTOMFeature"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<body>
<%-- start web service invocation --%><hr/>
<%
try {
    pkg.ImageWS_Service service = new pkg.ImageWS_Service(); 
    pkg.ImageWS port = service.getImageWSPort(new MTOMFeature(60000));
    

    // TODO initialize WS operation arguments here
    String filePath="C:/Picture/abcd2.jpg"; // Assuming this is the correct file path
    File file=new File(filePath);
    FileInputStream fis=new FileInputStream(file); 
    BufferedInputStream bis=new BufferedInputStream(fis); 
    String filename = file.getName(); 
    byte[]imageBytes=new byte[(int)file.length()]; 
    bis.read(imageBytes);
        port.upload(filename, imageBytes); 
    bis.close();
        out.println("File uploaded :" + filePath);
} catch (Exception ex) {
    // TODO handle custom exceptions here
    ex.printStackTrace();
}
%>
<%-- end web service invocation --%><hr/>
<%-- start web service invocation --%><hr/>
<%
try {
    pkg.ImageWS_Service service = new pkg.ImageWS_Service(); 
    pkg.ImageWS port = service.getImageWSPort();
        // TODO initialize WS operation arguments here
    String filename = "abcd2.jpg"; // Assuming this is the correct file name
    



    // Initialize filePath
    String filePath = "C:/Picture/download/" + filename; // Assuming this is the correct download path
        // Invoke the download method and get the file bytes
    byte[] fileBytes = port.download(filename);
        // Write the downloaded bytes to a file
    FileOutputStream fos = new FileOutputStream(filePath);
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    bos.write(fileBytes);
    bos.close();
        out.println("File downloaded: " + filePath);
} catch (Exception ex) {
    // TODO handle custom exceptions here
    ex.printStackTrace();
}
%>
<%-- end web service invocation --%><hr/>
</body>
</html>
 

Create a folder in C as Games
in this Games folder create 2 folders upload and download and paste 1 pic abcd.jpg in Games folder, initially the download anbd upload folder should be empty
make sure image (abcd.jpg) is present in path specified in index.jsp with same name 
run with green play button
