none
wcf does not handle JAXBElement <string> correctly RRS feed

  • General discussion

  • I need to pass a data contract to my wcf webservice from java client. The data contract has 2 filed both are string. After creating the proxies the code I am trying is below
       
        FileTransfer fs = new FileTransfer(); // 1 -- This is my service
        IFileTransfer ifs = fs.getBasicHttpBindingIFileTransfer();//2
        ServiceMessage request = new ServiceMessage();//3
        ObjectFactory factory = new ObjectFactory();//4
        JAXBElement<String> createfilename= factory.createString("myimg.txt");//5
        request.setFileName(createfilename);//6
        String returnfilename = ifs.uploadFile(request); //7
        System.out.println(createfilename.getValue()); //8
        System.out.println(returnfilename );//9 -- returns Null

    Here serviceMessage is the data contract. On typing 'request.' in eclipse I see a setfilename method(filename is one of the datamembers) to add the string I want to pass. But it accepts only JAXBElement type and not string. So in line 4 and 5 I try to convert my string to JAXBElement and pass it to the the service .
    Line 7 I am calling my web method which I have modifiled to return filename to check if my filename reaches the webservice correctly. But line 9 return null instead of the filename I have passed where as line 8 prints the file name correctly.
    My webmethod literally does just this

        return request.FileName;

    Can someone please help me undersand y even though I am sending the filename correctly (proof line 8) the webmethod returns Null

    Saturday, March 14, 2015 8:56 AM