|
Try to throw an exception and see the message... if ur not getting any exception then simply check the database table has rows or not.
catch (Exception ex)
{
throw;
}
|
|
|
|
|
hey u deleted your mail ID ,
i have to mail u that code ,
and i have used that exception, i am redirecting to Error.aspx if any error comes.
you once again give me ur mail id
thanks
|
|
|
|
|
|
Hi All,
I have a .net class library which makes call to a web service. I am trying to write unit tests (methods) for the methods of that class library. But the test methods are giving exceptions. Like the code is not ready or some thing like that. But when I call those methods from a asp.net web page all the methods are giving correct values. Means the class library is able to connect to the web service and executing it methods.
The exceptions that the test methods are saying is, "the proxy is not ready", I have added that web service by using "Add Web References". And one more thing is, I dont have "WSDL" utility in my machine so I coulnt create the proxy and I have added the web service using "Add Web References".
Can anybody help me in resolving the issue. Any help or any link or any advice is greatfull.
Thanks in advance.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
First, what you are doing isn't really unit testing, it is integration testing (as long as your architecture is good), but you can use unit tests to exercise this.
I actually don't recognise the actual error you give - is it the actual message? I'm assuming the error is with the proxy accessing the server.
First: Is your test config pointing at the server?
Second: Is your sevice running under the web server built into Visual Studio: http://stevennagy.spaces.live.com/blog/cns!B2EFDBF0964586B3!198.entry?sa=436582379[^] If so, when you run your unit tests the server isn't necessarily running - and this might cause your problem ().
As for the wsdl.exe - it should be installed alongside VS, it is part of the .Net Framework Tools[^]. That said, I've used a web reference in the past without any problems.
If you give the actual error text, you'll have more chance of getting an answer.
|
|
|
|
|
Hi,
I will explain what I am doing again
I have a class library called DataAccess, this clas library is accesing few web methods. I need to test the methods of the class library "DataAccess". If I remove the web servcie call from the "DataAccesss" class library then Unit tests are working fine. But When I keep the Web service call in the method and run the unit test its giving the following error.
"Test method HireXpress.DataAccess.Test.LawLogicDataAccessClassTest.WS_SubmitNewHireTest threw exception: System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required..
at System.Net.HttpWebRequest.GetRequestStream(ref TransportContext context)
at System.Net.HttpWebRequest.GetRequestStream()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at HireXpress.DataAccess.gaurdianservice.Guardian.WS_SubmitNewHire(Int32 inComKey, String inComPW, String[] inEmpData, ref String outResultMsg) in Reference.cs: line 149
at HireXpress.DataAccess.LawLogic.LawLogicDataAccessClass.WS_SubmitNewHire(ref String outResultMsg, Int32 inComKey, String inComPW, String[] inEmpData) in LawLogicDataAccessClass.cs: line 15
at HireXpress.DataAccess.Test.LawLogicDataAccessClassTest.WS_SubmitNewHireTest() in LawLogicDataAccessClassTest.cs: line 140"
Please help me in resolving it, I am struck here. Pls help me.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
OK, this is a very different error to the one in the OP. The key line in the stack trace is:
indian143 wrote: System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required..
For some reason the proxy is configured in such a way that it needs web-proxy access to get to the web-service sever (effectively the web service is not logged into a web-proxy server).
1. Check the config file in your test project. Make sure it points to the correct service address, this is the likely source of the error. If the server is local, it almost certainly doesn't need a web proxy set up.
2. Ensure your hosts file maps localhost to 127.0.0.1
3. If your service sits on a different IP to the client but on the same network, make sure that you configure the proxy access in IE to bypass for the destination address
4. If you genuinely need to supply a proxy service (i.e. your security policy forbids access to the destination address without logging in to the proxy) you will need to configure proxy login.
Without knowing your network setup it is difficult to help more, not only that I'm off to bed (1am here). Hope this helps[edit] - my post helping I mean, not the fact I'm off to bed!
|
|
|
|
|
Hi Keith,
Thanks for your support, which country are you in now .
Yeah I too came to a conclusion that it is might be because of security set up. One more question I have is "Do I have to set any properties at the time of Web Referencing?". Because it is clear that they are using https means secured socket layer. Do I need to make any settings at the time of creating Web Reference. If so can you please let me know those things.
Thanks once again for the sort of support you are giving me. Thanks a lot may God bless you in all corners your of life.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
indian143 wrote: Thanks for your support, which country are you in now
No problem, people join here to do this. I'm living in Jordan right now, I'm part developer part uni lecturer.
indian143 wrote: Do I have to set any properties at the time of Web Referencing
Not at the time of referencing, but you will have to do extra work at the time you consume the service if you need to provide security information. I'm afraid it has been a long time since I've used vanilla Web Services (I moved everything to WCF as soon as I could, my last asmx work was in 2006) so my memory is very sketchy about all this, and the framework will have moved on as well. My memory seems to be faulty, I would have sworn that you set up security credentials for the client in the web/app config (this is the case with WCF), but I couldn't find this for web services anywhere.
Anyway I did a bit of digging here are two pages that might be of use:
http://geekswithblogs.net/mnf/articles/108602.aspx[^]
Connect to a web service through a Proxy Server[^]
Hope they help!
|
|
|
|
|
WSDL.EXE gets installed when you install either a Visual Studio edition other than Express, or a Windows SDK (which are freely downloadable).
|
|
|
|
|
I dont have admin privileges, they would ask for the reason to give admin privileges. Cant I run the unit test cases if I dont have WSDL.exe or proxy. I think in Web references also VS.Net would cerate a proxy. Thats what references may be. But the web service call is not hitting the method in in the reference.cs file.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
you are right, WSDL.exe seems to require admin rights no matter what you want it to do for you, which doesn't make much sense to me.
|
|
|
|
|
You don't need to generate the proxy using WSDL directly, the web reference should just work. If you have proxy classes available this is proof.
Your "restricted" environment is could well be causing your problem- see my reply to your post: For some reason the client is trying to connect to the service via a web proxy that it has no authorisation for.
|
|
|
|
|
Hi,
In VS.Net IDE, if I am in a particular .cs or .aspx file in a particular project considering that application or solution is having lot of projects included in it. Now I want to know is there any short cut key to see that particular branch or project. Because its making me lot of problem, I am getting that particular project by saying my file as save as then seeing whole path and then going to that particular project.
Is there any short cut key to go to that project directly without doing all these things. Like If we want to go to the previous visited line in VS IDE press Ctrl+hyphen. Like this I want to know how to go to the project directly in the solution explorer using any short cut keys.
Thanks in advance.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
Been doing C# for years - but this is the first time I've needed to do a web app so I'm trying ASP.NET for the first time.
I have a listview bound to a SqlDataSource. My SelectCommand needs to be something like "SELECT .... FROM ... WHERE Field LIKE '%value%'
I have ControlParameter tied to a textbox that will be the value used in the LIKE clause.
Here is my question:
If I code my SelectCommand to look like ......WHERE Field LIKE '%' + @value + '%'
It works, but if somebody types a value like O'Hara into the text box - it will choke due to the concatenation (and I'm pretty sure open me up to SQL injection attacks)
If I code my SelectCommand to look like ......WHERE Field LIKE @value
It will work perfectly if I manually type the % signs in the text box for value. Including if I type %O'Hara% (the single quote no longer chokes it since I'm not concatenating anymore) - but obviously I don't want to have to teach the world to always put % sings at the start and end of their search strings on my web site.
So what is the best place to concatenate the % signs at the start and end of my search string?
This must be a VERY VERY COMMON thing to do. What are others doing about this?
|
|
|
|
|
Figmo2 wrote: I have ControlParameter tied to a textbox
Instead, tie parameter to a string variable. Set the string variable to the value of the text box, and then replace every singe ' with '' (ie escape out the single quotes in the input criteria. You can thyen use WHERE Field LIKE '%' + @value + '%' without exposing yourself to any injection attacks.
|
|
|
|
|
|
Figmo2 wrote: If I code my SelectCommand to look like ......WHERE Field LIKE @value It will work perfectly if I manually type the % signs in the text box for value. Including if I type %O'Hara% (the single quote no longer chokes it since I'm not concatenating anymore) - but obviously I don't want to have to teach the world to always put % sings at the start and end of their search strings on my web site.
I think this is correct functionality, it is looking for records where Field contains "%....%" rather than "....". I don't see the need to manually type the "%" in the majority of cases, it'll just confuse most [non-technical] users. Do you need to use wildcards?
|
|
|
|
|
Great suggestions all - thank you. What I ended up doing was a little different. I think elegant, but maybe not. Open to critiques...
I left the ControlParameter tied to my text box. (the parameter is called @SearchExpr)
My WHERE clause in the SelectCommand is simply "...WHERE Field LIKE @SearchExpr..." (no concatenation, thus no problems with single quotes needing to be escaped)
And added an event handler for SqlDataSource.Selecting that does this...
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)<br />
{<br />
e.Command.Parameters["@SearchExpr"].Value = "%" + e.Command.Parameters["@SearchExpr"].Value + "%";<br />
}
So now the user just enters ANY search string into the text box (e.g. "O'Hara")
This is passed to the SelectCommand as a parameter, thus it is not executable code - so no worries about SQL injection (I think)
And then, in the event handler, right before the SelectCommand is applied to the SqlDataSource, I modify the value to add the % signs front and back.
It works like a charm but the only thing I am not certain of is how well protected I am against injection attacks. Am I right in assuming that this should be adequate protection?
|
|
|
|
|
Figmo2 wrote: Am I right in assuming that this should be adequate protection?
You're using a parameterised query, so you should be OK on that front. However, take a look at http://msdn.microsoft.com/en-us/library/ms179859.aspx[^] for some more "magic characters" that might appear in your search string, and give unexpected results.
|
|
|
|
|
Hi All,
I had a task which is compare the customer age in the background and if he is 18+ then I have to show
him he is allowed for a new feature(this is typically a click link which in turn call another service) if he is under 18 then there is no display of new feature.
Client asked me to present that new feature to please the people who are eligible.
I have done all the background tasks except the presentation.
my code struck here
if(age>18)
{
///////////
}
Any suggestions????
Thanks
-- Modified Tuesday, October 5, 2010 10:06 AM
|
|
|
|
|
Jayadheer Reddy wrote: my code struck here
if(age>18)
{
///////////
}
use some link or linkbutton or tab according to your page need and display it in only when your condition gets true.
|
|
|
|
|
Hello I have a gridview with this form
ID_student -------exam_mark1 ------exam_mark2-----average
to calculate the average score I used this code
double average = 0;<br />
foreach (GridViewRow MRow in GridView1.Rows)<br />
{<br />
average = double.Parse(MRow.Cells[2].Text ) + double.Parse(MRow.Cells[3].Text);<br />
average = average / 2;<br />
MRow.Cells[4].Text = moyenne.ToString();<br />
}
but it returns me the following error: The format of the input string is incorrect.
Help me ,thanks
|
|
|
|
|
the Cells collection is zero-based, so you want to average Cells(1) and Cells(2) adn put the answer in Cells(3), not 2, 3 adn 4 as you have it.
But what a horrible way of doing things...on teh sassumption that these results are pulled from a database, why not pull the average directly out of that in your select statement?
Or at least calculate the average in teh RowDataBound event....
|
|
|
|
|
amina89 wrote: but it returns me the following error: The format of the input string is incorrect.
Did you try to debug your code? Debugging if for this purpose only.
As already suggested, better to do this calcaluation and assiging in rowdatabound event.
|
|
|
|