Web Service queries

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • E11esar
    New Member
    • Nov 2008
    • 132

    Web Service queries

    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 :)
  • E11esar
    New Member
    • Nov 2008
    • 132

    #2
    A bit more..

    Also with the above, is it always necessary to have the port number in the web address for the web server?

    Thank you.

    Mark :)

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      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

      Comment

      • E11esar
        New Member
        • Nov 2008
        • 132

        #4
        Web service

        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 :)

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          First compile your application, then publish it using Visual Studio... see if that helps.

          Comment

          • E11esar
            New Member
            • Nov 2008
            • 132

            #6
            Me again

            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 :)

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              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?

              Comment

              • balabaster
                Recognized Expert Contributor
                • Mar 2007
                • 798

                #8
                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.

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #9
                  Originally posted by balabaster
                  ...
                  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.

                  ...
                  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

                  Comment

                  • E11esar
                    New Member
                    • Nov 2008
                    • 132

                    #10
                    Wsdl

                    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 :)

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #11
                      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.

                      Comment

                      • E11esar
                        New Member
                        • Nov 2008
                        • 132

                        #12
                        Originally posted by Frinavale
                        If you don't want to expose your methods publicly, then privately tell the people the URL of where your web service is hosted.
                        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 :)

                        Comment

                        • Frinavale
                          Recognized Expert Expert
                          • Oct 2006
                          • 9749

                          #13
                          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.

                          Comment

                          • balabaster
                            Recognized Expert Contributor
                            • Mar 2007
                            • 798

                            #14
                            Originally posted by Frinavale
                            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.
                            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.

                            Comment

                            • Frinavale
                              Recognized Expert Expert
                              • Oct 2006
                              • 9749

                              #15
                              Originally posted by balabaster
                              ... and it was one of those "who the hell's bright idea was that?" moments...
                              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.

                              :)

                              Comment

                              Working...