Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing my first webservice using VS 2008 and .Net 3.5.

My webservice code is as follows:


Service1.asmx
=============
C#
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.Services;
using System.Web.Services.Protocols;
using CAQHBAMWriter;
using Microsoft.Win32;
using System.Resources;
using System.Diagnostics;


namespace BAMWriterService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://BAMWriterService/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
   
    public class Service1 : System.Web.Services.WebService
    {
        [WebMethod]
        [SoapDocumentMethod(OneWay = true)]
        public void WriteToBam(BAMDataObject dobj)
        {
            BAMWriter bamWriter = new BAMWriter();
            bamWriter.writeToBamDatabase(dobj.getArraylist(), dobj.getActivityName());

        }
    }

BAMDataObject.CS
================
C#
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;

namespace BAMWriterService
{
    [Serializable]
        public class BAMDataObject
        {

        protected  List <Dictionary <string,string>> list;
            protected String activityname;

            public void setArraylist(List<Dictionary<string, string>> list)
            {
                this.list = list;
            }
            public void setActivityName(string activityname)
            {
                this.activityname = activityname;
            }

            public List<Dictionary<string, string>> getArraylist()
            {
                return this.list;
            }
            public String getActivityName()
            {
                return this.activityname;
            }
        }
    }
}

My client code is:

I added the service reference to the above service.
The following is the few lines where i call the service. The problem is that two methods of BAMdataobject is not there (setarraylist and setactivitylist)

C#
try
{
    BAMWriterService.BAMDataObject dObj = new BAMWriterService.BAMDataObject();
    dObj.setArraylist(dataList);
    dObj.setActivityName(activityNme);
    BAMWriterService service = new BAMWriterService();
    service.WriteToBam(dObj);
}
Posted
Updated 19-Dec-09 22:36pm
v2

your chain of code seems convoluted to me. Have you tried adding a WebMethod flag to the methods in question ? Either way, what is the purpose of the BAMDataObject class ? Do you return data as instances of this class ? What happens if the set methods have not been called ? This code seems poorly thought out to me. If I created a data object class, I'd have a constructor that took the required data, so the object could not exist without that data having been set.
 
Share this answer
 
your chain of code seems convoluted to me. Have you tried adding a WebMethod flag to the methods in question ? Either way, what is the purpose of the BAMDataObject class ? Do you return data as instances of this class ? What happens if the set methods have not been called ? This code seems poorly thought out to me. If I created a data object class, I'd have a constructor that took the required data, so the object could not exist without that data having been set.

1 Have you tried adding a WebMethod flag to the methods in question
- yes I have added the webmethod flag to setArraylist and setActivityName() in bamddataobject. What I did is that i removed the bamdataobject class and moved the code into service. I get an error on SetArraylist since the i am using Dictionary which is not supported.

2. what is the purpose of the BAMDataObject class ?
- The purpose of this class to set the data from the client side. Then call the function WriteToBam by passing the BAMDataObject.

3. What happens if the set methods have not been called?
- There will not be data set for the service.
 
Share this answer
 
What I meant was, why do you have a seperate class. And what I was trying to point out is, your design does not protect itself from being used incorrectly, as far as I can see. The overall design seems poor to me. I was trying to help you to see that.
 
Share this answer
 
Your client only has access to the WriteToBam. It doesn't have access to a class that the .asmx references. If you want to give it access you have to write a public method/function that calls the class in the .asmx.
 
Share this answer
 
wrote:
first webservice using VS 2008 and .Net 3.5.


If I were you and using VS2008 and .Net 3.5, I would not build an asmx web service. I would build a WCF service[^].
 
Share this answer
 
yes i think it make sense, but i don't under the code in side
try { BAMWriterService.BAMDataObject dObj = new BAMWriterService.BAMDataObject(); dObj.setArraylist(dataList); dObj.setActivityName(activityNme); BAMWriterService service = new BAMWriterService(); service.WriteToBam(dObj); }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900