469,364 Members | 2,471 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,364 developers. It's quick & easy.

Web Service queries

132 100+
Hi there.

I have written a web service in C# (VS2008) and ASP.Net and all is working fine with it. The problem I am having is when I expose the web service and hence then try to subscribe to its methods from a test application.

When I start up the web service in VS2008, the url has the usual address-type of http://localhost:3998/Webservice1/Service.asmx.asmx and so I am finding that if I wish to use the web methods in my test application, then I have to Add a Web Reference and copy/paste in the full url to the test application.

I feel this is the wrong way to do things so as I ultimately want to publiush this web service for other people to use, the question is how do I do this and where do I place all the necesary files? Do I have to use the Build/Publish web site option with the web service? It is then how do I see the web service on a different machine? Hopefully you get the idea with what I am looking for here..?

Most books and the such seem to give examples of the web service and corresponding subscribing apps to be on the same machine.

Thank you.

M :)
Dec 15 '08 #1
17 1909
E11esar
132 100+
Also with the above, is it always necessary to have the port number in the web address for the web server?

Thank you.

Mark :)
Dec 15 '08 #2
Frinavale
9,735 Expert Mod 8TB
Hi there :)

Check out this article on deploying web services.

You need a web server running IIS.
You then publish (or manually move) the Web Service to the web server.
The client that consumes the web service must know the URL that the web service has been published/moved to. For simplicity sake, use that URL to reference the web service in your application by copy/pasting the URL (or using the "add web reference"). I think there is a way around this using a Look Up Service but how to do this is escaping me right now (it's been a while since I've developed with web services).

You are only going to need to specify the port if you are running the Web Service on a special port (other than port 80 I think).

-Frinny
Dec 15 '08 #3
E11esar
132 100+
Thank you for that. In terms of the web service, will this be http://machine-ip-number/WebService1/Service.asmx..?

I ask this as if I go to the virtual directory in IIS and right-click the respective asmx file and select Browse, I get the error:

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

A name was started with an invalid character. Error processing resource 'http://localhost/AddSearch/Service.asmx'. Line 1,...

<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="Service" %>
-^

Thank you.

Mark :)
Dec 15 '08 #4
Frinavale
9,735 Expert Mod 8TB
First compile your application, then publish it using Visual Studio... see if that helps.
Dec 15 '08 #5
E11esar
132 100+
Hi there. This is a new machine I am using and so asp was not registered in IIS, so that has solved that problem :)

I just need to get this working so that an external third party can pick up my webservice, which has to be located on a database server as the web service is acting like an API in effect and enabling data to be extracted from the database via the exposed methods of the web service..?

Hopefully that makes a little more sense.

Thank you.

Mark :)
Dec 15 '08 #6
Frinavale
9,735 Expert Mod 8TB
Exposing methods over the web which let 3rd party applications access your data is what Web Services are all about.

The only thing that the 3rd party has to know is where to get the WSDL that describes how to access your Web Service....so that they are able to create a Proxy that calls your functions. They get the WSDL from the URL where the service is hosted.


Are you still having problems?
Dec 15 '08 #7
balabaster
797 Expert 512MB
In my experience, it seems that web services don't work quite in the manner you might initially expect. For instance, I have a webservice that does an address verification, including spell checking against the full Canada Post database, correcting things like street name and type based on a confidence level. It creates a weighting based on the corrected spelling of the street, the street type the postal code, the street number range and provides back a corrected address to reduce errors and omissions and duplicated data in our database without forcing our users to know every piece of information and spell it correctly.

So, I wanted to be able to just provide this as an external webservice that you could call from a JavaScript/AJAX call. However, due to potential XSS (Cross Site Scripting) security precautions, I wasn't able to complete this task in the manner I would've originally prefered.

How I had to go about this was to add a web reference to my "external" application and create a webservice proxy that interfaced with my main webservice. This isn't exactly ideal, but I couldn't find another method to do this... if you come up with a way to do it directly in the manner I'd originally prefered - please post it here.

So up to this point the only way I've found to link to my web service is to add this web reference to my external application and point it to my master web service that does all the heavy lifting. My proxy webservice then provides an interface to this web service providing WebMethods that take data in from my AJAX call and pass it off to my master service and then receives the data back and passes the output back to my AJAX's callback method.

This is the method that most of the documentation I've come across allows you to do this, and it's understandable given the XSS security issues. If you've got a service that you want to open to the public though, I imagine there's a setting somewhere that allows you to override the XSS security and open it up - I just never found it.
Dec 15 '08 #8
Frinavale
9,735 Expert Mod 8TB
@balabaster
I haven't actually used a web service in an asp.net application. Even though I know it's possible... I have only ever created a desktop application that consumes the web service.

Anyways, from what I understand is that you have to create a proxy in order to call the web methods...this is just how it works.

I think you're solution's fine...until MS comes up with a better way to handle calling web services from web-browser clients.

-Frinny
Dec 15 '08 #9
E11esar
132 100+
I suppose my next question is how do I let them know where the WSDL is?

Sorry for being so daft here but normally I just write the program or web service and somebody else does all the admin-related work for me.

I see there is a WSDL command that can be run but then I read that Visual Studio is supposed to do all that for me, so I think that is part of my confusion as I'm not quite sure what and where I need to do the publication part of ther web service.

Once published, I then want to fire up a test client and run the web service methods from there, but again it is knowing how to reference the other machine and hence its web service that is causing confusion.

Thank you.

Mark :)
Dec 15 '08 #10
Frinavale
9,735 Expert Mod 8TB
Like I said it's been a while since I've used Web Services.

Here are some keywords to use while searching for ways to expose your web service:
  • web service Lookup
  • UDDI

If you don't want to expose your methods publicly, then privately tell the people the URL of where your web service is hosted.
Dec 15 '08 #11
E11esar
132 100+
@Frinavale
Okay last question and then I'll go away and do more research: is the URL the machine name or do I have to do additional work so that the target machine can host the webs ervice please?

Thank you.

Mark :)
Dec 15 '08 #12
Frinavale
9,735 Expert Mod 8TB
You can use the Machine name if the 3rd party is connecting to the web service on your local network.

If your 3rd party will be connecting from the outside world you will have to reference it differently. You'll have to use the IP of the computer instead of the machine name.

Please note that I'm not talking about a local network IP (like 192.168.1.x) If your web server's located on a network, you will have to configure it to pass the request through to the computer hosting the web service.

Also please note that most IP addresses are not static and are subject to change.

Look into using something like No-IP...so that you can get around using an IP as the URL to your web service.
Dec 15 '08 #13
balabaster
797 Expert 512MB
@Frinavale
Yeah, that's what I concluded too... and it was one of those "who the hell's bright idea was that?" moments. I notice there are some JavaScript libraries that allow you to consume services from the client side, but it would be nice if you didn't have to go to all that effort and could just call them directly using the XmlHttpObject.
Dec 15 '08 #14
Frinavale
9,735 Expert Mod 8TB
@balabaster
I have a lot of those moments... although, for me, its more of a question of "Why" rather than "Who".

I don't think they were originally designed with the idea that they would called directly from web pages. It would be cool if MS looked into this though.

:)
Dec 15 '08 #15
balabaster
797 Expert 512MB
There are so many of those... I come across one at least once a day where I think "why am I not on the .NET design team?"... a lot of the framework is really well implemented with specific tasks in mind, but they fall just a little short in many areas that I would consider common tasks.

I'd like to think that they're not just "common" in my world as I write software in many different industries.
Dec 15 '08 #16
vinot85
53
Hi buddy,
There is something called UDDI. Wherein we will discover the services.
Jan 8 '09 #17
Frinavale
9,735 Expert Mod 8TB
@vinot85
:) that's already been suggested in post 11 :)
Jan 8 '09 #18

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Polaris | last post: by
7 posts views Thread by Chris Mullins | last post: by
2 posts views Thread by Sourcerer | last post: by
2 posts views Thread by =?Utf-8?B?UGllcnJl?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.