CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15

Thread: WebService

  1. #1
    Join Date
    Jul 2006
    Location
    Mnila, Philippines
    Posts
    171

    WebService

    I have a confusion guys, are WebServices runs only in server side?

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: WebService

    Web Service runs on a Server and has Web Methods that are executed on the server. What is the confusion?

  3. #3
    Join Date
    Jul 2006
    Location
    Mnila, Philippines
    Posts
    171

    Re: WebService

    Ok thanks, I think it runs in client and server side depending to the set-up of the developer. So it safe if I will code my connection string of my database into web service.?

  4. #4
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: WebService

    The webservice does run server side, and replies with XML (SOAP) via the webmethod calls Shuja Ali mentiosn.

    Therefore the client can't see what is going on in the webservice and you can safely allow the webservice access to your connection string.

  5. #5
    Join Date
    Jul 2006
    Location
    Mnila, Philippines
    Posts
    171

    Re: WebService

    I see, so the web service creates an xml output going to the client... How about the soap xml below, can I manipulate it in my web form and pass to the web service? How can I change its Content-Length?...Sorry guys, I have a big confusion about soap. Its my first time to code ASP.Net. I already output to the client my database using webmethod.

    Code:
    POST /MyWebService/Service.asmx HTTP/1.1
    Host: localhost
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://localhost:1563/MyWebService/GetTableValue"
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <GetTableValue xmlns="http://localhost:1563/MyWebService" />
      </soap:Body>
    </soap:Envelope>
    
    
    ***********************************************************
    
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <GetTableValueResponse xmlns="http://localhost:1563/MyWebService">
          <GetTableValueResult>
            <ResourceValues>
              <ResourceID>string</ResourceID>
              <Plant_PMin>decimal</Plant_PMin>
              <Plant_PMax>decimal</Plant_PMax>
              <Mean>decimal</Mean>
              <SD>decimal</SD>
            </ResourceValues>
            <ResourceValues>
              <ResourceID>string</ResourceID>
              <Plant_PMin>decimal</Plant_PMin>
              <Plant_PMax>decimal</Plant_PMax>
              <Mean>decimal</Mean>
              <SD>decimal</SD>
            </ResourceValues>
          </GetTableValueResult>
        </GetTableValueResponse>
      </soap:Body>
    </soap:Envelope>

  6. #6
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: WebService

    Quote Originally Posted by sweet_babylhyn View Post
    How about the soap xml below, can I manipulate it in my web form and pass to the web service?
    I do not understand what you mean by this. This XML would be returned by the Web Service and you can use it in your Web Form. What is it that you want to pass back to Web Service?

    Also please understand, that while writing Web Services, you don't have to worry about how SOAP works (although it helps if you know it, but it is not a pre-requisite). You can write a Web Method that returns a DataSet and then in your client app you can use the dataset like any other dataset that you create locally.

  7. #7
    Join Date
    Jul 2006
    Location
    Mnila, Philippines
    Posts
    171

    Re: WebService

    ah ok, but it is possible to pass an xml file which contain records into webservice and the webservice will automatically save it into my database table? (Can use also update, delete or retrive data in database and return its output into xml file). Do you have any idea to do this...

  8. #8
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: WebService

    Yes it is possible to pass XML to the web service. The basic concept of web services runs on top of XML so you should be ok with passing XML to your web service.

  9. #9
    Join Date
    Jul 2006
    Location
    Mnila, Philippines
    Posts
    171

    Re: WebService

    I can pass dataset easily, I used the code below but when I try to pass xml file, it return me an error.

    Code:
    <WebMethod()> _
        Public Function GetDatasetSet() As DataSet
            Dim DTFinal As New DataTable
            Dim DSFinal As New DataSet
            Dim cnn As String = "DATA SOURCE=192.168.0.10:80;USER ID=uid;password=pwd"
            Dim oraCnn As New OracleConnection(cnn)
            Dim oraCmd As New OracleCommand("SELECT * FROM table1")
            Dim adapter As OracleDataAdapter
    
            Try
                oraCnn.Open()
                oraCmd.Connection = oraCnn
                adapter = New OracleDataAdapter(oraCmd)
                adapter.Fill(DTFinal)
    
            Catch ex As OracleException
                MsgBox("Can not Connect to the Datatabase", MsgBoxStyle.Critical, "Check Connection")
                Throw
            Finally
    
                oraCnn.Close()
            End Try
    
            DSFinal.Tables.Add(DTFinal)
            Return DSFinal
        End Function

    This comes an error...

    Code:
    <WebMethod()> _
        Public Function GetXML(byval tmpXML as XML) As XML
            ........
            .........
            .........
          return FinalXML
       end function

    Do you have any suggestion or much better ideas... BTW, I used framework 2.0
    Thanks
    Last edited by sweet_babylhyn; April 23rd, 2009 at 04:02 AM.

  10. #10
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: WebService

    What error do you get?

    And FYI, you should edit your post and remove the IP address from your connection string to not display what IP/Port number you use.

  11. #11
    Join Date
    Jul 2006
    Location
    Mnila, Philippines
    Posts
    171

    Re: WebService

    hmmm! If I pass an xml file, do I have to use this ...

    Code:
    public function PassXML(byval objXML as XmlDocument) as aXmlDocument
    I have a difficulty in XML manipulation because the XML will be created during runtime and it will not save in hardrive. Once it created, it will pass to the webservice to manipulate and return new xml which again not save in hardrive.

    I can serialize and deserialize xml if I will save/get it to hardrive but I hard time if I will do it in runtime without saving it to disk...

    Do you have any idea to do this?... I searched already in net but all of my example manipulate
    the xml coming from hardrive.

  12. #12
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: WebService

    You can pass XML as a string to the Webservice. This is the simplest way of doing it. Something like this
    Code:
    <WebMethod()> _
        Public Function GetXML(ByVal tmpXML as String) As String
            ........
            .........
            .........
          return FinalXML
       end function

  13. #13
    Join Date
    Jul 2006
    Location
    Mnila, Philippines
    Posts
    171

    Re: WebService

    Thanks for your reply and I will give my feedback when it done.

  14. #14
    Join Date
    Jul 2006
    Location
    Mnila, Philippines
    Posts
    171

    Re: WebService

    It works already.... Another question, how can I get the method request by the client if it is POST or GET. I want to use REST in my webservice.

    Code:
    http://www.parts-depot.com/parts/00345
    it will return to the client the details about "00345"

    Code:
    <?xml version="1.0"?>
    <p:Part xmlns:p="http://www.parts-depot.com"   
            xmlns:xlink="http://www.w3.org/1999/xlink">
          <Part-ID>00345</Part-ID>
          <Name>Widget-A</Name>
          <Description>This part is used within the frap assembly</Description>
          <Specification xlink:href="http://www.parts-depot.com/parts/00345/specification"/>
          <UnitCost currency="USD">0.10</UnitCost>
          <Quantity>10</Quantity>
    </p:Part>

  15. #15
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: WebService

    You should go through this tutorial, it will help a lot in the long run
    http://www.codeproject.com/KB/archit...icesPart2.aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured