Advertisement

01.11.2008 at 12:48PM PST, ID: 23076885
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

WebService namespace problem

Asked by SeTech in Extensible Markup Language (XML), Programming for ASP.NET, Visual Studio

Tags:

I am a 100% newbie at web services, attempting to write my first one, that is supposed to take the place of (and expand the functionality of) a class library my predecessor in my department developed.

However, I am getting an error message when I try to add a Web Reference to my service in another project (that message should be attached) about the XML element in the namespace I dictated, and I don't have this element ANYWHERE in the service. Now, after googling (and searching EE as well) for the problem, it seems that the problem stems from some of my WebMethods returning DataSets or SqlDataSources (both are returned by various methods in the service).

I know basically next to nothing about XML and little more about web services, I'm a very C#-oriented kinda guy. So any answers, I'm afraid, mst be boiled down to layman's terms, as aggravating as I'm sure that must be.

Thanks in advance for any help you can offer. I'm attaching the web service code for reference.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
 
[WebService(Namespace = "http://www.allstate.com/seroroad")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
    #region Variables
    private string DevConStr = @"[string snipped for security]";
    private string ProdConStr = @"[string snipped for security]";
    private SqlConnection conn = new SqlConnection();
    private string smtpserver = "mail.allstate.com";
    private int rows;
    private string _user;
    private string _domain;
    private string _group;
    private string _full_name;
    private string _fulgrp;
    private string _phone;
    private bool _isManager;
    private bool _isProxy;
    #endregion
 
    public Service()
    {
        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }
 
    #region Get methods for variables
    [WebMethod]
    public string user()
    {
        return _user;
    }
 
    [WebMethod]
    public string domain()
    {
        return _domain;
    }
 
    [WebMethod]
    public string group()
    {
        return _group;
    }
 
    [WebMethod]
    public string full_name()
    {
        return _full_name;
    }
 
    [WebMethod]
    public string fulgrp()
    {
        return _fulgrp;
    }
 
    [WebMethod]
    public string phone()
    {
        return _phone;
    }
 
    [WebMethod]
    public bool is_Manager()
    {
        return _isManager;
    }
 
    [WebMethod]
    public bool is_proxy()
    {
        return _isProxy;
    }
    #endregion
 
    [WebMethod]
    public void init(bool production, string ntid)
    {
        // Set connection string to Connection
        if (production)
        {
            conn.ConnectionString = ProdConStr;
        }
        else
        {
            conn.ConnectionString = DevConStr;
        }
 
        // Set user and domain based on passed-in variable
        int whereIsSlash;
        whereIsSlash = ntid.IndexOf("\\");
        _domain = ntid.Substring(0, whereIsSlash);
        _user = ntid.Substring(whereIsSlash + 1, (ntid.Length - whereIsSlash - 1));
 
        // Call sp_getuserinfo
        SqlParameter[] sqlPz1 = new SqlParameter[1];
        sqlPz1[0] = new SqlParameter("@search", _user);
        DataSet ds = sp_anything("[secdb].[dbo].[sp_getuserinfo]", sqlPz1);
 
        #region Population
        // Populate group, full_name, phone, is_manager and is_proxy
        try
        { 
            _group = ds.Tables[0].Rows[0].ItemArray[8].ToString(); 
        }
        catch 
        { 
            _group = "orphan"; 
        }
        try 
        { 
            _full_name = ds.Tables[0].Rows[0].ItemArray[1].ToString() + ", " + ds.Tables[0].Rows[0].ItemArray[0].ToString(); 
        }
        catch 
        { 
            _full_name = "unknown"; 
        }
        try 
        { 
            _phone = "(" + ds.Tables[0].Rows[0].ItemArray[2].ToString() + ") " + ds.Tables[0].Rows[0].ItemArray[3].ToString() + "-" + ds.Tables[0].Rows[0].ItemArray[4].ToString(); 
        }
        catch 
        { 
            _phone = "unknown"; 
        }
        try 
        { 
            _isManager = (bool)ds.Tables[0].Rows[0].ItemArray[6]; 
        }
        catch 
        { 
            _isManager = false; 
        }
        try 
        { 
            _isProxy = (bool)ds.Tables[0].Rows[0].ItemArray[7]; 
        }
        catch 
        { 
            _isProxy = false; 
        }
 
        // Call sp_getgrpinfo
        SqlParameter[] sqlPz2 = new SqlParameter[1];
        sqlPz2[0] = new SqlParameter("@search", _group);
        DataSet ds2 = sp_anything("[secdb].[dbo].[sp_getgrpinfo]", sqlPz2);
 
        // Set fulgrp
        try 
        { 
            _fulgrp = ds2.Tables[0].Rows[0].ItemArray[0].ToString(); 
        }
        catch 
        { 
            _fulgrp = "orphan";
        }
        #endregion
    }
 
    #region Executing Stored Procedures
    [WebMethod]
    public DataSet sp_anything(string procedure, SqlParameter[] paramz)
    {
        DataSet ds = new DataSet();
        SqlCommand cmd = new SqlCommand(procedure, conn);
        cmd.CommandType = CommandType.StoredProcedure;
        try
        {
            if (paramz != null)
            {
                foreach (SqlParameter param in paramz)
                {
                    cmd.Parameters.Add(param);
                }
            }
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
        }
        catch (Exception exc)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("An error occurred inside SeWebSec v 3.0; method sp_anything");
            sb.AppendLine("Source: " + exc.Source);
            sb.AppendLine("Message: " + exc.Message);
            sb.AppendLine("Inner Exception: " + exc.InnerException);
            sb.AppendLine("Stack Trace: " + exc.StackTrace);
            sendmail(_user, "seweb@allstate.com", "SeWebSec v3.0 Error", sb.ToString());
        }
        finally
        {
            if (conn != null)
                conn.Close();
        }
        return ds;
    }
 
    [WebMethod]
    public void sp_anyNoReturn(string procedure, SqlParameter[] paramz)
    {
        SqlCommand cmd = new SqlCommand(procedure, conn);
        cmd.CommandType = CommandType.StoredProcedure;
        try
        {
            if (paramz != null)
            {
                foreach (SqlParameter param in paramz)
                {
                    cmd.Parameters.Add(param);
                }
            }
            conn.Open();
            rows = cmd.ExecuteNonQuery();
            conn.Close();
        }
        catch (Exception exc)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("An error occurred inside SeWebSec v 3.0; method sp_anyNoReturn");
            sb.AppendLine("Source: " + exc.Source);
            sb.AppendLine("Message: " + exc.Message);
            sb.AppendLine("Inner Exception: " + exc.InnerException);
            sb.AppendLine("Stack Trace: " + exc.StackTrace);
            sendmail(_user, "seweb@allstate.com", "SeWebSec v3.0 Error", sb.ToString());
        }
        finally
        {
            if (conn != null)
                conn.Close();
        }
    }
 
    [WebMethod]
    public object sp_single(string procedure, SqlParameter[] paramz)
    {
        SqlCommand cmd = new SqlCommand(procedure, conn);
        cmd.CommandType = CommandType.StoredProcedure;
        object vague = null;
        try
        {
            if (paramz != null)
            {
                foreach (SqlParameter param in paramz)
                {
                    cmd.Parameters.Add(param);
                }
            }
            conn.Open();
            vague = cmd.ExecuteScalar();
            conn.Close();
        }
        catch (Exception exc)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("An error occurred inside SeWebSec v 3.0; method sp_single");
            sb.AppendLine("Source: " + exc.Source);
            sb.AppendLine("Message: " + exc.Message);
            sb.AppendLine("Inner Exception: " + exc.InnerException);
            sb.AppendLine("Stack Trace: " + exc.StackTrace);
            sendmail(_user, "seweb@allstate.com", "SeWebSec v3.0 Error", sb.ToString());
        }
        finally
        {
            if (conn != null)
                conn.Close();
        }
        return vague;
    }
    #endregion
 
    [WebMethod]
    public void sendmail(string from, string to, string subject, string body)
    {
        try
        {
            MailMessage mm = new MailMessage(from, to, subject, body);
            mm.IsBodyHtml = false;
            SmtpClient smtp = new SmtpClient(smtpserver);
            smtp.Send(mm);
        }
        catch
        {
            SqlParameter[] sqlparams = new SqlParameter[4];
            sqlparams[0] = new SqlParameter("@From", from);
            sqlparams[1] = new SqlParameter("@Subject", subject);
            sqlparams[2] = new SqlParameter("@Body", body);
            sqlparams[3] = new SqlParameter("@To", to);
            sp_anyNoReturn("[dbo].[sp_send_cdosysmail]", sqlparams);
        }
    }
 
    #region getDataSourceForGrids and overrides
    [WebMethod (MessageName="selectOnly")]
    public SqlDataSource getDataSourceForGrids(string select)
    {
        SqlDataSource sds = new SqlDataSource("System.Data.SqlClient", conn.ConnectionString, select);
        return sds;
    }
 
    [WebMethod (MessageName="withUpdate")]
    public SqlDataSource getDataSourceForGrids(string select, string update, Parameter[] updateParams)
    {
        SqlDataSource sds = new SqlDataSource("System.Data.SqlClient", conn.ConnectionString, select);
        sds.UpdateCommand = update;
        sds.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure;
        if (updateParams != null)
        {
            foreach (Parameter param in updateParams)
            {
                sds.UpdateParameters.Add(param);
            }
        }
        return sds;
    }
 
    [WebMethod (MessageName="withUpdateAndInsert")]
    public SqlDataSource getDataSourceForGrids(string select, string update, Parameter[] updateParams, string insert, Parameter[] insertParams)
    {
        SqlDataSource sds = new SqlDataSource("System.Data.SqlClient", conn.ConnectionString, select);
        sds.UpdateCommand = update;
        sds.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure;
        if (updateParams != null)
        {
            foreach (Parameter param in updateParams)
            {
                sds.UpdateParameters.Add(param);
            }
        }
        sds.InsertCommand = insert;
        sds.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
        if (insertParams != null)
        {
            foreach (Parameter param in insertParams)
            {
                sds.InsertParameters.Add(param);
            }
        }
        return sds;
    }
    #endregion
 }
 
Loading Advertisement...
 
[+][-]01.11.2008 at 11:12PM PST, ID: 20643087

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Extensible Markup Language (XML), Programming for ASP.NET, Visual Studio
Tags: The XML element 'EnableTheming' from namespace 'http://www.allstate.com/seroroad' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element.
Sign Up Now!
Solution Provided By: codeclay
Participating Experts: 1
Solution Grade: A
 
 
[+][-]01.14.2008 at 05:50AM PST, ID: 20652835

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628