locked
Using Webservices RRS feed

  • Question

  • User-1758489868 posted

    Hello,

    I am new to the world of webservices, so am probably going to be asking some dumb-seeming questions!

    I have been handed some (WSDL?) generated code which is supposed to be a SOAP Webservices wrapper for some API functions.  It has generated a partial class with a method that looks like this:

            <System.Web.Services.Protocols.SoapHeaderAttribute("mws"),  _
             System.Web.Services.Protocols.SoapDocumentMethodAttribute("AddBatchHead", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Bare)>  _
            Public Function AddBatchHead(<System.Xml.Serialization.XmlElementAttribute("AddBatchHead", [Namespace]:="http://schemas.lawson.com/OIS100TEST/AddBatchHead")> ByVal AddBatchHead1 As AddBatchHeadCollection) As <System.Xml.Serialization.XmlArrayAttribute("AddBatchHeadResponse", [Namespace]:="http://schemas.lawson.com/OIS100TEST/AddBatchHead"), System.Xml.Serialization.XmlArrayItemAttribute("AddBatchHeadResponseItem", IsNullable:=false)> Object()
                Dim results() As Object = Me.Invoke("AddBatchHead", New Object() {AddBatchHead1})
                Return CType(results(0),Object())
            End Function


    When I call it with someting like this:

    myResults = myWebServicesWrapper.AddBatchHead(myCollection)

    Everything seems to work OK.  The bit I am stumbling over is that the webservice is supposed to return the output from the API function call in the System.Object() myResults.  It probably does, but its in a System.Object type, which doesn't seem to expose anything about the contents of the object (.toString just gives you 'System.Object' - the type not the contents).  I have tried a few Ctype or DirectCasts to get the results into a more helpful format, but that always fails with something like "Unable to cast object of type 'System.Object' to type 'System.String'" or somesuch.  Can anyone suggest what I should eb doing here?  How are you supposed to consume the returned System.Object() data from these calls?  Am I just casting to the wrong target?

    Any info you can provide would be gratefully appreciated,

    Thanks,

    Iain



    Friday, July 5, 2013 1:54 AM

Answers

  • User-1360095595 posted

    If you put a breakpoint on that line and them examine myResults you should be able to see what the underlying type is. If that doesn't prove helpful if get in touch with whoever gave you the wsdl and ask them. I'm pretty sure they'll be able to tell you immediately. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 5, 2013 2:13 AM

All replies

  • User-1360095595 posted

    If you put a breakpoint on that line and them examine myResults you should be able to see what the underlying type is. If that doesn't prove helpful if get in touch with whoever gave you the wsdl and ask them. I'm pretty sure they'll be able to tell you immediately. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 5, 2013 2:13 AM
  • User527778624 posted

    Hi,

    Try to avoid using Object type, and use custom type only.

    Check these sites for info:

    http://forums.asp.net/t/1812910.aspx/1

    http://stackoverflow.com/questions/15546496/which-data-types-are-allowed-to-return-from-wcf-web-service

    Friday, July 5, 2013 2:22 AM
  • User-1758489868 posted

    Thanks for the quick response (MetalASP.NET). 

    I'm running this in an older version of BIDS (as part of as SSIS package) and the script debugging seems to be knackered, so I can't hit any breakpoints.  I have been making do with msgboxs for all my debug :(

    Unfortunately, its the guy that gave me the WSDL that is asking me how to get the return value, so might not be much help.  I will ask him to show me how it was generated and see whether the tool that spits these out provides info about what return types to expect.

    I am assuming it is a case of knowing what the returned type within the System.Object is and casting to that type to use the returned data - is that correct?

    Thnaks,

    Iain

    Friday, July 5, 2013 2:24 AM
  • User-1758489868 posted

    Thanks raju dasa.

    The code for AddBatchHead is entirely tool generated - do you think its worth going through editing all of the instances where the System.Object type is returned and reworking them to use a more specific type, or can I leave the generated codes as-is and deal with the System.Objects that are returned?

    Thanks,

    Iain

    Friday, July 5, 2013 2:30 AM
  • User-1758489868 posted

    Thanks for the help MetalASP.Net.  It was a bit of config missed out when generating the Web Service (the AddBatchHeadResponseItem mentioned in thecode I posted as the return types wasn't being generated) so there was no available type that could receive the returned value.  Once this was corrected and the Web Reference was regenerated, it was possible to use the returned value in the script.

    Thanks!

    Monday, July 8, 2013 2:04 AM