Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
B

BASONJS

@BASONJS
About
Posts
11
Topics
7
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • JSP page - fill bean - to servlet
    B BASONJS

    Hi all, I have been trying to find this out for 4 days straight, doing all types of research and yet I cannot find it, although it seems like one of the most fundamental things I can think of. I am new to jsps and servlets but not new to java, so please be patient with me _____________________________________________________ SCENARIO: 1) I have an index.jsp page with a form with 1 field for the user to fill up. 2) I have a bean which I am trying to fill up from the index page itself. 3) I have a servlet that handles the request _____________________________________________________ INDEX PAGE:

    <%@ page import="com.java2s.*"%>

    What's your name?

    _____________________________________________________ BEAN:

    package com.java2s;

    public class bean {
    String username;

    public void setUsername( String value )
    {
        username = value;
    }
    
    public String getUsername() 
    { 
        return username; 
    }
    

    }

    _____________________________________________________ SERVLET:

    package com.java2s;

    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;

    public class MyServlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException 
    {
    
        HttpSession session = request.getSession(true);
        // Get the bean from the session
        bean myBean = (bean)session.getAttribute("bean");
    
        // if the bean is not in session instantiate a new bean
        if (myBean == null)
        {
            myBean = new bean();
            myBean.setUsername("FAILED");
        }
    
        request.setAttribute("bean", myBean);
        request.getRequestDispatcher("test.jsp").forward(request, response);
    }
    

    }

    ____________________________________________________ PROBLEM: I get the bean in the servlet, that is to say: bean myBean = (bean)session.getAttribute("bean"); actually returns an object and not null, thats not a problem. The proble

    Web Development java database com help question

  • Web Service web.config variables from dll in bin folder
    B BASONJS

    Hi all, I have a question regarding web services and configuration files. Platform: .Net Framework , code behind c#. Scenario: I have a web service which when i publish, creates a bin folder. All normal. Now, in that bin folder i have a dll which is effectively my data access layer, CRUD for databases etc. Now i use ConfigurationManager.GetSection("AppConfig") within this dll in order to get database connection strings, which the dll brings out from the web service web.config file. File Structure: <My Web Service Folder> --><AppData> --><bin>--><My Data Access Layer DLL> --><web.config(includes data access layer variables)> Within my development environment, this works like a charm, using ConfigurationManager.GetSection("AppConfig") from my dll to get out the appconfig section from my web.config and then searching the nodes in order to find the right key. Example of web.config: <AppConfig> <Configs use="true"> <add key="Databases" use="true" /> </Configs> <!-- Web Service Configuration Settings--> <Databases> <ConnectionStrings> <add key="<MY KEY NAME>" providerName="System.Data.SqlClient" value="<MY CONNECTION STRING>" /> </ConnectionStrings> </Databases> </AppConfig> So far so good. Now i am testing a deployment of this system on a virtual pc. I copy and paste the c:\initpub\<mywebservice> folder into the c:\inetpub of the virtual pc. I try and run it and it fails. After inserting debugging into the code to see where it is failing, I found out that ConfigurationManager.GetSection("AppConfig") is actually returning null instead of the appconfig section from the web.config. Does anybody know why this is happening ? Please excuse the length of the post but was needed to explain the situation. James

    C# csharp question workspace database dotnet

  • Custom Classes in web services
    B BASONJS

    Hi all, I have a problem with custom classes in web services. The scenario is as follows: I have created custom classes for use with my environment. We will take as an example, class student and class teacher which are in the package MyPackage.Data. These are being serialised at location A, passed to the web service and then sent to location B. While at the web service, the object is deserialised in order to extract info about the object to keep a log of what is going through. When the object is deserialised in the web service and then reserialised to send to location B (this also happens when creating a new object at the web service and sending it out to a location), the type of the object turns into MyWebservice.Student instead of MyPackage.Data.Student. I get exceptions like: "Cannot cast object of type MyWebservice.Student to MyPackage.Data.Student". I am guessing this is being taken from the reference file which is autogenerated on instantiation of a web service. An example of this auto generated code is shown below for the Student class

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3053")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="MyPackage.Date")]
    public partial class Student{

        private string Name;
        
        /// <remarks/>
        public string Name{
            get {
                return this.name;
            }
            set {
                this.name= value;
            }
        }
        
    }
    

    Now for this I used a work around, writing an alternate constructor for each class which takes an object of type MyWebservice.Student for example and creates a new instance of of MyPackage.Data.Student and sets all attributes to the attributes of the MyWebservice.Student object. An example is shown below:

     public Starter(MyWebservice.Student webStudent)
     {
         this.name  = webStudent.Name;
     }
    

    This works but is neither pleasant nor viable as a final solution. Can anybody please shed any light on how not to use the generated code of the web service or remove it completely or why this is happening. Thanks a lot for your time and cooperation, any help is highly appreciated

    C# help wcf xml json tutorial

  • Dynamic XML Serialiser
    B BASONJS

    Hi guys, we are back. I have a small problem with xml serialization. Problem: I can serialize an object as the type is know from the object passed in to be serialized, but after this is passed through a webservice, deserialization is a problem, as the type of the object is not known. The objects which are being serialized are all custom objects. Scenario: I have a generic serializer class. The code found below:

        /// /// Method to convert a custom Object to XML string
        /// 
        /// Object that is to be serialized to XML
        /// XML string
        public String serializeObject(Object pObject)
        {
            try
            {
                String XmlizedString = null;
                MemoryStream memoryStream = new MemoryStream();
                XmlSerializer xs = new XmlSerializer(pObject.GetType());
                XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
                xs.Serialize(xmlTextWriter, pObject);
                memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
                XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
                return XmlizedString;
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
                return null;
            }
        } 
        
        /// /// Method to reconstruct an Object from XML string
        /// 
        /// 
        /// 
        public Object deserializeObject(String pXmlizedString)
        {
            XmlSerializer xs = new XmlSerializer(typeof(Object));
            MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
            XmlTextReader xmlTextReader = new XmlTextReader(memoryStream);
            return xs.Deserialize(xmlTextReader);
        } 
    

    When I am serializing the object, this works fine, as I can create a serializer with the object type from the object:

    XmlSerializer xs = new XmlSerializer(pObject.GetType());

    But when I come to deserialize the object from a string, I see two options which both dont work. Either:

    XmlSerializer xs = new XmlSerializer(typeof(Object));

    Which gives me a " not expected error" as the serializer obviously doesnt know about my custom class. Or:

    C# help xml json

  • Object "type not expected" when using serialization in web services
    B BASONJS

    I have got to this point. The classes are all now in this format:

    using System;
    using System.Collections;
    using System.Xml.Serialization;
    using System.Xml;

    namespace Data.Package
    {
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "Data.Package", TypeName = "Changes")]
    public class Changes
    {
    private Boolean blnIsDirty;
    private Boolean blnIsNew;

        public Changes() 
        {
            this.blnIsDirty = false;
            this.blnIsNew = true;
        }
    
        \[System.Xml.Serialization.XmlElementAttribute(ElementName = "IsDirty")\]
        public Boolean IsDirty
        {
            get { return blnIsDirty; }
    
            set { blnIsDirty = value; }
        }
    
        \[System.Xml.Serialization.XmlElementAttribute(ElementName = "IsNew")\]
        public Boolean IsNew
        {
            get { return blnIsNew; }
    
            set { blnIsNew = value; }
        }
    }
    

    }

    My serialization class is as follows:

    using System;
    using System.Text;
    using System.Xml.Serialization;
    using System.IO;
    using System.Xml;

    namespace Helper
    {
    public class Serializer
    {
    public Serializer()
    {

        }
    
        /// /// Method to convert a custom Object to XML string
        /// 
        /// Object that is to be serialized to XML
        /// XML string
        public String serializeObject(Object pObject)
        {
            try
            {
                String XmlizedString = null;
                MemoryStream memoryStream = new MemoryStream();
                XmlSerializer xs = new XmlSerializer(pObject.GetType());
                XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
                xs.Serialize(xmlTextWriter, pObject);
                memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
                XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
                return XmlizedString;
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
                return null;
            }
        } 
        
        /// /// Method to reconstruct an Object from XML string
        /// 
        /// 
        /// 
        public Object deserializeObject(String pXmlizedString)
        {
    
    C# help tutorial wcf sysadmin xml

  • Object "type not expected" when using serialization in web services
    B BASONJS

    I have done as you suggested and am still getting the same error. The problem now I believe is the way I am serialising the object. I have made a custom class for this: using System; using System.Text; namespace Helper { public class Serializer { public Serializer() { } /// /// Method to deserialise an object from a string of hex characters /// /// /// the object which was deserialised public Object DeserialiseObject(String hex) { System.IO.MemoryStream stream2; System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bformatter2 = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); byte[] array = HexStringToByteArray(hex); stream2 = new System.IO.MemoryStream(array); Object obj = bformatter2.Deserialize(stream2); stream2.Close(); return obj; } /// /// Method to serialise an object into a hex string /// /// /// public string serializeObject(Object temp) { //write it to stream System.IO.MemoryStream stream2 = new System.IO.MemoryStream(); System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bformatter2 = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); bformatter2.Serialize(stream2, temp); byte[] array = new byte[stream2.Length]; array = stream2.ToArray(); String hex = ByteArrayToHexString(array); stream2.Close(); return hex; } /// /// Helper to change a byte array to a hex string /// /// /// string of hex characters private static string ByteArrayToHexString(byte[] Bytes) { StringBuilder Result; string HexAlphabet = "0123456789ABCDEF"; Result = new StringBuilder(); foreach (byte B in Bytes) { Result.Append(HexAlphabet[(int)(B >> 4)]); Result.Append(HexAlphabet[(int)(B & 0xF)]); } return Result.ToString();

    C# help tutorial wcf sysadmin xml

  • Object "type not expected" when using serialization in web services
    B BASONJS

    no at the moment the objects are as follows:

    using System;
    using System.Runtime.Serialization;
    using Person;

    namespace SchoolPackage
    {
    [Serializable()]
    public class Student : ISerializable
    {
    private Person person;
    private int intReference;
    private int intReqTypeID;
    //
    private string strLastAlteredByUser;
    private DateTime dteAlteredDate;
    private Boolean blnIsDirty;
    private Boolean blnIsNew;
    private enum RequestType : int
    {
    Create = 1, Delete = 2, Update = 3, Execute = 4,
    Retrieve = 5, RetrieveMultiple = 6
    }

        public Student(Person person, String user, int TypeID, int Reference) 
        {
            this.person = person;
            this.strLastAlteredByUser = user;
            this.dteAlteredDate = DateTime.Now;
            this.blnIsDirty = false;
            this.blnIsNew = true;
            this.intReqTypeID = TypeID;
            this.intReference = Reference;
        }
      
        //Deserialization constructor.
        public Student(SerializationInfo info, StreamingContext ctxt)
        {
            //Get the values from info and assign them to the appropriate properties
            person = (Person)info.GetValue("person", typeof(Person));
            action = (string)info.GetValue("action", typeof(string));
            intReference = (int)info.GetValue("intReference", typeof(int));
            intReqTypeID = (int)info.GetValue("intReqTypeID", typeof(int));
        }
                
        //Serialization function.
        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {            
            info.AddValue("person", person);
            info.AddValue("action", action);
            info.AddValue("intReference", intReference);
            info.AddValue("intReqTypeID", intReqTypeID);
        }
    

    }

    C# help tutorial wcf sysadmin xml

  • Object "type not expected" when using serialization in web services
    B BASONJS

    Hi all, Hope I am posting this in the right forum. I seem to be having a problem when using serialization and web services. Scenario: I have built a web service which includes a multitude of web methods. All the web methods have various parameters, but one parameter which they all have in common is an 'object' parameter. This is due to the fact that the web service works differently according to the type of object being passed into it. Now as for the objects, I have constructed a set of custom classes which satisfy my need. For example's sake, let us say we have: Teacher class Student Class LectureRoom Class Lecture Class We will call these the "School Package classes" I am then wrapping these classes within other custom classes which I use not only to transport my objects around but also to keep track of statuses etc. Example: Request Class Response Class The school package classes would be serialized and saved within the request or response class. So effectively, the objects which the web service really sees are the request and response classes which will in turn have the school package classes inside of them. The Problem: The problem is found when a school package object is passed within the response and request object. On deserialisation or transportation of these objects, the web service always throws an exception as follows: {"System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically. From what I could gather and the research I have done, the problem lies with the web service not knowing of the object types at compile time. Make Shift Solution: For a quick and dirty solution I created methods within the web service which use the object types needed. For Example: public void Junk(Student myStudent){} This seemed to have worked, but is not what I want, as with about 40 custom classes, this is both horrible coding and very tedious. I have also tried researching the xmlinclude and soapinclude found in the System.Xml.Serialization library, but dont really know how to use these. I have tried adding them above the web service class declaration and the web methods which use the objects in this format: [XmlInclude(typeof(Student))] But yet to no

    C# help tutorial wcf sysadmin xml

  • WebService to Webservice 2
    B BASONJS

    Hi all, I have a web service which I want to implement on multiple servers and which can communicate with each other. (Meaning reusing the same web service on the different servers) I am currently using a proxy class which i created with wsdl.exe in order to call the web service from any other component (web page, windows service, etc). That works fine, giving it the Url. Now the problem I have is communicating between one web service and another, as when I add the proxy class to the web service, in order to create an instance of a webservice and give it a URL, the namespaces, functions etc already have definitions for them. To simplify: Web page to web service communication Web page has web service proxy class, an instance of web service is created, a url is given and the web service methods called - works fine Web Service to Web service communication I add the proxy class to the web service and it gives me errors, namespace already defined, etc etc, obviously because the proxy class is of the same web service I am trying to add the class to. So effectively my question is this. In order to reuse my web service over multiple servers and call methods between these web services, what do I have to do? Thank you very much in advance for any help

    C# wcf help question

  • Webservice To Webservice
    B BASONJS

    fantastic stuff. Thank you very much for your help :) James

    C# question database sysadmin help

  • Webservice To Webservice
    B BASONJS

    Hi. I have created a component group consisting of a web service, windows service, database, etc. Each of these units(the component group being one unit) will be installed on a server (meaning each server will have a windows service, web service, database, etc). In order to call and use the web service I have consumed it and used it as a normal object. Ex: ExampleWebService myWebservice = new ExampleWebService(); myWebservice.Create(); Now my question is here. I have a part of my program which reads the webservices' URLs from a database, and needs to call each webservice in order to check if its still alive or not, a kind of heartbeat monitor if you will. From one webservice, how do I call another, knowing its URL and by consuming it ? Any help will be greatly appreciated, thanks.

    C# question database sysadmin help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups