Link to home
Start Free TrialLog in
Avatar of scubamikey
scubamikey

asked on

Web service that accepts on XML Doc as input parameter

Hi,
Is there any standard possibility to pass XML document as an input argument
to the web-service?

 I want to develope a Web-service that will have XML as an argument and I want to develope a client application that will pass XML to the web-service.
******************************************************************************
<WebMethod()> _
    Public Function getOrders(ByVal myXML As Xml.XmlDocument) As Xml.XmlDocument
        Dim myDoc As New Xml.XmlDocument
        Dim myErr As New Xml.XmlDocument
        myDoc = (myXML)
        ImportFile(mydoc)
        Return (myErr)

    End Function
I am getting this error message from the server:

**************************************************************
<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <soap:Fault>
      <faultcode>soap:Server</faultcode>
      <faultstring>Server was unable to process request. --&gt; Object reference not set to an instance of an object.</faultstring>
      <detail />
    </soap:Fault>
  </soap:Body>


Thanks
Avatar of Dabas
Dabas
Flag of Australia image

Hi scubamikey,
Have you tried to send a dataset instead of an xmlDocument?
I have had no problem doing it that way. On the client side you can read your XMLDocument into a dataset, then pass the dataset as a parameter.

I suspect that the error you are getting tends to suggest that the myXML object you are sending to your WebMethod as a parameter did not get initialized at the client

Dabas
Avatar of scubamikey
scubamikey

ASKER

Dabas,

I am trying to program web service to my clients," Trading partner specs." The sender of the data is sending a SOAP document in xml.
Any suggestion on how I can read what they are trying to send to me?

Thanks for the quick response,

ScubaMikey
scubamikey,
> Object reference not set to an instance of an object
This means that an object has not been initialised. Usually happens if you forget to create an object with the New keyword.
Since your code seems to be OK, I have the feeling that the incoming myXML document comes in as nothing.
The other place that might be faulty is in the non supplied ImportFile.

Suggestions:
1) Use a try catch block, to find out exactly which line is causing the problem
2) Add an if statement at the start of your function that checks if myXML is nothing:
If myXML is Nothing then
   Create a new XMLDocument, add a suitable error message to it and return it
End If
....

3) Check if the error is not happening inside the ImportFile Method

Dabas
I Will try this & update you on the results.
Thanks
SM
Dabas
We are on the right track. This helped track down where the error is. Can help me with a client app that wil send a test xml Doc the my web service.
I am able to test what I have so far by load a test file on the remote web server & read in the file in like this:
WebMethod()> _
    Public Function getOrders(ByVal myXML As Xml.XmlDocument) As Xml.XmlDocument
        Dim myDoc As New Xml.XmlDocument
        Dim myErr As New Xml.XmlDocument
        myDoc.Load("E:\cxxxx2b\SampleRequest1.xml")
        'myDoc = (myXML)
        'Throw New SoapException("Message was 3RECEIVED", SoapException.ClientFaultCode)
        If myDoc Is Nothing Then
            Throw New SoapException("Message was 3RECEIVED", SoapException.ClientFaultCode)
        Else
            ImportFile(myDoc)
            Throw New SoapException("Message was complete", SoapException.ClientFaultCode)
        End If
But when I try to pass my sample xml doc on a client app, I get my error. here is my client app:

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
       
        'Dim mydoc As xml
        Dim ws As New citi.myXML
        ' Dim myXML As
        ws.ReadXml("C:\ATC\SampleRequest1.xml")
        ws.getOrders(citi.myXML)

How can I pass the xml Doc correctly?

SM
scubamikey,
What is citi.myXML? Seems to be a user defined class.
You are sending a myXML, but you are receiving a XML.XmlDocument.

Dabas
citi.myXML is the class web reference for my web service. : i.e. ...service1.asmx

Maybe I am not understanding the difference or where to go from here.
How can I send a xml file to my web service as the web service input parameter?

SM
scubamikey,
    OK. ws is the reference to your web service.
Do you have another WebMethod named ReadXML? Can you post its code?

Where is C:\ATC\SampleRequest1.xml? On the client or on the webserver?

Dabas
Dabas,

Thanks for sticking with me on this one.

This is the code on my workstation my "client app"
*******************************************************
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
       
        'Dim mydoc As xml
        Dim ws As New citi.myXML ** web reference class "citi" parameter myXML !!! this is what I need to pass myXMLdoc to
        ' Dim myXML As
        ws.ReadXml("C:\ATC\SampleRequest1.xml")            ***LOAD IN XML DOC****
        ws.getOrders(citi.myXML)                                       ***send it back to web service as parameter*****
-------------------------------------------------------------------------------------------------------------------------------
ws.Readxml("C:\ATC\SampleRequest1.xml") ---is the only way that  I know how to "load in"  or" read in" a valid xml Document

I want to send this file / document to my web service. Everytime I send or invoke this procedure, I get the error (from the web-server/Web service)
>Server was unable to process request. --&gt; Object reference not set to an instance of an object.</faultstring

Scubamikey
scubamikey,
We are going around in circles

Please answer two simple questions:

1) The fact that you do not get an error on the line
ws.ReadXML("...") means that your webservices exposes a ReadXML method. Please supply its code so that I can help you further.

2) You have not yet answered my question as to where the xml file is. On the client (the computer that runs the program) or on the server (the computer that runs the web service)

Dabas
Sorry for the confusion:

1. Now that I look at it, ws.ReadXML(".. ") is not correct.
Here is the code behind from my web reference: for my class "citi." (located on my client app on my workstation)
------------------------------------------------------------------------------------------------------------------------------
<System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/service1/getOrders", RequestNamespace:="http://tempuri.org/service1", ResponseNamespace:="http://tempuri.org/service1", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)>  _

        Public Function getOrders(ByVal myXML As System.Xml.XmlNode) As System.Xml.XmlNode
            Dim results() As Object = Me.Invoke("getOrders", New Object() {myXML})
            Return CType(results(0),System.Xml.XmlNode)
        End Function
-----------------------------------------------------------------------------------------------
2. This file is located on my workstation.---> ("C:\ATC\SampleRequest1.xml").
I want to send /Post this file to my Web service, (located on a remote web server). ,as a test file.
How can I correct my code to make this happen?
I think I need to Read the file in and post it to the web service. Correct?

Any help you my provide would be appreciated/

SM
ASKER CERTIFIED SOLUTION
Avatar of Dabas
Dabas
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ding Ding Ding. Now I get It

Thank you

Scubamikey