-
[RESOLVED] [Workaround found] Easy: Pass string arg to Webservice
All,
I made a webservice and can Invoke the HelloWorld that gets made by the IDE. I also made a Webmethod that returns a record set thing and that seems to work fine, I can breakpoint in the code and everything.\
However the following Webmethod does not work with the string argument:
Code:
[WebMethod] public byte[] FilePickUp(string sFileName)
{
string sFilePath="C:\\Temp\\Dave.png";
byte[] byteContent = null;
try
{
if (IsFileExist(sFilePath) == true)
{
FileStream fs = new FileStream(sFilePath, FileMode.Open, FileAccess.ReadWrite);
byteContent = new byte[fs.Length];
fs.Read(byteContent, 0, (int)fs.Length);
fs.Close();
}
else
{
byteContent=new byte[1];
byteContent[0]=0;
}
}
catch(Exception ex)
{
throw ex;
}
return byteContent;
}
However, if I remove the string argument, I can call the Webmethod just fine.
The Webmethod compiled with the string argument shows a text box under the Invoke button when I run from the IDE. However pressing Invoke just causes a nasty error:
HTML Code:
The page cannot be displayed
There is a problem with the page you are trying to reach and it cannot be displayed.
--------------------------------------------------------------------------------
Please try the following:
Open the localhost:1639 home page, and then look for links to the information you want.
Click the Refresh button, or try again later.
Click Search to look for information on the Internet.
You can also see a list of related sites.
HTTP 500 - Internal server error
Internet Explorer
So when I remove the string argument I can call the Webmethod just fine, and get the .PNG junk dumped back into my browser.
Any ideas?
-
Re: Easy: Pass string arg to Webservice
Hi I tried your code , and I didn´t get a 500 internal server error.
The only thing I change was
try
{
if (File.Exists(sFilePath) == true)
{
-
1 Attachment(s)
Re: Easy: Pass string arg to Webservice
See the thing is, if I have a no argument to the WebService, then I can breakpoint and step through the code.
However, using a string as an argument, I cannot even break to the 1st line of code... I just get the erroneous web page...
-
Re: Easy: Pass string arg to Webservice
Hey,
When you have made the change to the WebService, have you updated the Web Reference in the application you are calling the Web Service from? If you haven't, then the Proxy Class that Visual Studio generates for you will not include the additional parameter that you have included in the method.
In solution explorer, right click on the Web Reference and click Update, that should sort you out.
Failing that, try using something like SoapUI, to independently test the Web Service.
Hope that helps!!
Gary
-
5 Attachment(s)
Re: Easy: Pass string arg to Webservice
OK please refer to my attachements.
I was unable to right-click anything in my solution explorer that offered to update my web reference. That is strange since I've seen that before recently, but not here.
So I can set breakpoints on the 2 WebServices that do basically nothing.
I can run the Hello world from the IDE/webbrowser, and get to a breakpoint.
But if I run another function with an int or string or something as an argument, and pass it into the web browser and press Invoke, I get some kind of crash, and do not even reach the breakpoint.
Next post I will show my Solution Explorer.
-
1 Attachment(s)
Re: Easy: Pass string arg to Webservice
Last post denied my a 6th image.
-
3 Attachment(s)
Re: Easy: Pass string arg to Webservice
Ah, I thought you might have had another application, like a web application that you added a reference to the Web Service in, in which case you would have something like this:
Attachment 71073
However, I am slightly confused by what you are showing in your solution explorer?!?! How did you go about creating the Web Service in the first place? I would have thought the contents should look something more like this:
Attachment 71072
It looks like you have simply added a .asmx file to an existing website. I don't know the ramifications of doing that, but it could be that what you are seeing is a symptom of that. I would have thought you should have selected the Web Service Application Template from the New Project wizard here:
Attachment 71074
Gary
-
1 Attachment(s)
Re: Easy: Pass string arg to Webservice
Well, I go to File-> New ... Website, ASP.NET WebService. Should I be doing it differently?
-
Re: Easy: Pass string arg to Webservice
Hey,
Ah, I see where the difference is coming in now.
I tend to not create new sites, but rather web applications. You get to this by hitting File | New Project, rather than File | New Web Site.
I have just created a Web Service in the way that you have, and I can confirm that it works as I would expect it.
Can you perhaps re-create the application, listing all the things that you do, to see if you can get it to work.
Gary
-
1 Attachment(s)
Re: Easy: Pass string arg to Webservice
No actually I cannot do that (yet?)
I tried it but I get these options only on File-> New Project... (see image).
So I figure something up with SP or something, so I go to the SP1 download here.
Thats my URL after d-loading. But then I see this URL: Microsoft Visual Studio 2005 - Update to Support Web Application Projects.
I will install them both then see where that gets me.
-
Re: Easy: Pass string arg to Webservice
Hey,
Just to confirm, what version of Visual Studio are you using?
Gary
-
Re: Easy: Pass string arg to Webservice
I don't have the packaging handy here. How can I tell? I thought I had the best version we could buy, but we did get an "upgrade" version. The retailer assured us it can co-exist with my installed version of VS 2003.
-
Re: Easy: Pass string arg to Webservice
OK, the SP1 installer says Visual Studio Proffessional Edition in the title bar. I think that's what we have.
-
Re: Easy: Pass string arg to Webservice
If you hit Help | About, you should be able to find out exactly what version you have.
Different Version's of Visual Studio can definitely live on the same machine, I have Visual Basic 6, Visual Studio 2003, Visual Studio 2005 and also Visual Studio 2008 on the same machine.
Gary
-
1 Attachment(s)
Re: Easy: Pass string arg to Webservice
OK after installing SP1, now when I do File-> New Project... I get the new options (see image).
And checking Help-> About I see indeed I do have Proff. edition.
I will try your advice to make a WebAppProj.
-
Re: Easy: Pass string arg to Webservice
Ok, sounds good.
Try doing the same thing with the new Application Template and see how you get on.
On a side note, it's good to try and keep Visual Studio up to date, as you get the the benefit of all the new additions, as well as security fixes. If you use Microsoft Update, rather than Windows Update, any new updates for Visual Studio will be included.
Good luck with the Web Service, post back if you are still having problems.
Gary
-
Re: Easy: Pass string arg to Webservice
If I make a Web Service Application, will I still get a web service? I am making Web Services for sonsumption by non-MS clients (FLEX actually).
-
Re: Easy: Pass string arg to Webservice
Yes you will still get a web service. Have a look here for a discussion on the differences in using Web Applications:
http://blogs.vertigosoftware.com/tea...1/03/4057.aspx
Also, as I mentioned earlier, have a look at SoapUI. This will allow you to independently verify the operation of the Web Service. SoapUI is a java application, and I have found it to be a great tool for testing my web services, and best of all, it's free :)
Gary
-
3 Attachment(s)
Re: Easy: Pass string arg to Webservice
Ugh - same problem. Made new WebService Application this time, added a simple WebMethod:
Code:
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
namespace WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string HelloWorldInt(int argc)
{
return "Hello World";
}
}
}
But still I cannot Invoke the method with an int for an argument...!!!
-
Re: Easy: Pass string arg to Webservice
Hey,
I am really sorry, but I really don't know what to tell you...
I have literally copied and pasted the code that you have there into a new project, and it works. Out of curiosity, can you try SoapUI, or some other way of testing the Service outside of Visual Studio and Internet Explorer?
Gary
-
1 Attachment(s)
Re: Easy: Pass string arg to Webservice
OK so I noticed theres no Web Reference so in the project explorer, I Add Web Reference... after I publish this to my localhost.
I browse to it and get this wierdo error:
Code:
There was an error downloading 'http://localhost/WebService1/Service1.asmx'.
The request failed with the error message:
--
<html>
<head>
<title>Configuration Error</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana"
-
Re: Easy: Pass string arg to Webservice
Hey,
In this instance, you don't need a Web Reference. You only need a Web Reference if you are trying to consume the Web Service from another application, such as a Windows Form Application, or a Web Application. Here you are testing the Web Service as a stand alone entity using the built in mechanism within ASP.Net.
Doing what you are doing here would essentially create a Web Reference to itself, which is not needed.
Gary
-
Re: Easy: Pass string arg to Webservice
OK I installed the other kb patch and still no luck. I rebooted and made a new Web Service Application. I can run the HelloWorld Web Mothod, but if I make a new one with any kind of parameter, I cannot Invoke it from the IDE/Browser.
Can you post your web.config?
Any other ideas?
-
Re: [Still Unresolved] Easy: Pass string arg to Webservice
Hey,
The web.config is just the one that is rolled out with the default template, I didn't make any changes to it:
Code:
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true" />
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows" />
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>
The only other suggestion would be as I said, test it with SoapUI, or it's equivalent. This would tell you whether this is an issue with the Web Service itself, or the testing mechanism that you are using.
Gary
-
Re: [Still Unresolved] Easy: Pass string arg to Webservice
Hey,
Out of interest, have you been able to get any further with this?
Were you able to try out SoapUI?
Gary
-
Re: [Still Unresolved] Easy: Pass string arg to Webservice
No further. Have not tried SoapUI yet. The web services work perectly fine when my FLEX clients or .NET clients access them, so it's not really a matter of whether or not the web services work.
This is mostly a pain-point for me as I like to test the things I create in the IDE in debug mode before I send them out for consumption.
-
Re: [Still Unresolved] Easy: Pass string arg to Webservice
Hey,
Yeah, I know what you mean, it is definitely good to be able to debug things as you are creating them. Have you got access to a colleagues machine that you could run a test on? I hesitate to suggest that there is something wrong with your setup, but it is looking more and more like that.
Gary
-
Re: [Still Unresolved] Easy: Pass string arg to Webservice
That is a great idea, but I have the only license and installation of VS 2005. I could possibly set VS up on a test system and see if the problem persists. I am really hoping that I just have something configured improperly.
I am pretty stumped.
-
Re: [Still Unresolved] Easy: Pass string arg to Webservice
Hey,
If you get a chance, you could try running a Virtual Machine with a fresh install of Visual Studio and see how you get on, and obviously, wipe the VM once you have completed your testing, so as to not break any licensing rules :)
I have got a standard installation of Visual Studio, and it worked out of the box, so I suspect it is something on your machine that is causing the problem. However, in these situations, by the time you have figured out exactly what is going on, you could have completely re-installed your machine.
Gary
-
Re: [Still Unresolved] Easy: Pass string arg to Webservice
If only our company was not too cheap to buy VMWare... I've been asking for it for a few years now.
-
Re: [Still Unresolved] Easy: Pass string arg to Webservice
Ha ha, we are lucky enough to have three ESX Servers in the building, but if you don't have the funds, download and install VMWare Server, it is completely free (after a registration) and let's you create and run VM's on your own laptop, you can find it here:
http://www.vmware.com/products/server/
I have it on my own machine for the times when the ESX Server isn't justified. You can use it solely on your own machine, or set it up on a machine that everyone can access. It has a web based interface which makes it very easy to configure. The one draw back is that you are only able to take on snapshot.
Gary
-
Re: [Still Unresolved] Easy: Pass string arg to Webservice
Update: I am using IE7 and I did reset to factory default settings, but still I am still having this problem.
If I publish the website to the server it works just fine. This problem is specific to running within the IDE only.
-
Re: [Still Unresolved] Easy: Pass string arg to Webservice
Are you admin on your machine?
Can you set your project (in properties > web tab) to use IIS virtual directories so that when you run it, it invoked an IIS address instead of the built-in web server?
-
Re: [Still Unresolved] Easy: Pass string arg to Webservice
Quote:
Originally Posted by
mendhak
Are you admin on your machine?
Can you set your project (in properties > web tab) to use IIS virtual directories so that when you run it, it invoked an IIS address instead of the built-in web server?
That sounded like a great idea, but when I tried it, I unfortunately get the same erroneous behavior!
Any other ideas? I'd really like to get past this problem...
Thanks!
-
Re: [Still Unresolved] Easy: Pass string arg to Webservice
To elaborate a bit, I did set up the project to run from an IIS VD as suggested.
I verified the VD was created an is using ASP.NET 2.0 in IIS.
If I click the play button (start debugging) from the IDE, the web service launches, and I can Invoke memebers with no arguments. But any member with any simple argument yields the same error page.
However if I use IE to browse to the web service, then I can Invoke the members with simple arguments and they work perfectly.
-
Re: [Still Unresolved] Easy: Pass string arg to Webservice
Oh yes I am an Admin on the machine. My user is member of Administrators and Debugger Users.
-
Re: [Still Unresolved] Easy: Pass string arg to Webservice
OK after some brute force random things I am trying I discovered that if I "start debugging" from the IDE it loads up an IE window pointing to the localhost/webservice, as normal.
However if I close that or minimize that and instead launch my own independant IE browser from the desktop shortcut, and browse to localhost/webservice, then I can call the members with simple arguments, and if I set a breakpoint, my IDE really does handle the call and breakpoints properly.
This odd discovery is enough to get around my problem, as now I can run quick tests of my service members, essentially from the IDE.
To be a stickler, my original problem is not solved, but this workaround is enough for me to resolve the thread.
Thanks to all!