Search code examples
javawebservices-client

Sending java object to c# web service


I am working on one project in which i am developing a java client for .NET/C#. I want to send information of device to the web service. I have created one class which contains the device information. I want to send the information of the device to service. what is appropriate way to do this. Please help.

sorry for my weak English. And thanks in advance.

package com.ivb.syntecApp.models;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class DeviceInformation {

    private String vendorId;
    private String productId;
    private String hardwareRevision;
    private String deviceName;
    private String manufacturerName;

    @XmlElement
    public String getVendorId() {
        return vendorId;
    }
    public void setVendorId(String vendorId) {
        this.vendorId = vendorId;
    }

    @XmlElement
    public String getProductId() {
        return productId;
    }
    public void setProductId(String productId) {
        this.productId = productId;
    }

    @XmlElement
    public String getHardwareRevision() {
        return hardwareRevision;
    }
    public void setHardwareRevision(String hardwareRevision) {
        this.hardwareRevision = hardwareRevision;
    }

    @XmlElement
    public String getDeviceName() {
        return deviceName;
    }
    public void setDeviceName(String deviceName) {
        this.deviceName = deviceName;
    }

    @XmlElement
    public String getManufacturerName() {
        return manufacturerName;
    }
    public void setManufacturerName(String manufacturerName) {
        this.manufacturerName = manufacturerName;
    }
}

Solution

  • I have solved at my own. I don't know is it good practice or not.

    My answer is ->

    I have used JAXB for marshaling DeviceInformation class and used `void marshal(Object jaxbElement, Writer writer) throws JAXBException

    ` to convert this object in to StringWriter object then converted it into string and sent this string to .NET/C# service. This meets my requirement.

    I found this here