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
scubamikeyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DabasCommented:
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
0
scubamikeyAuthor Commented:
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
0
DabasCommented:
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
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

scubamikeyAuthor Commented:
I Will try this & update you on the results.
Thanks
SM
0
scubamikeyAuthor Commented:
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
0
DabasCommented:
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
0
scubamikeyAuthor Commented:
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
0
DabasCommented:
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
0
scubamikeyAuthor Commented:
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
0
DabasCommented:
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
0
scubamikeyAuthor Commented:
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
0
DabasCommented:
scubamikey,
Back to one of my first comments. Remember I recommended you use a DataSet and pass that to your webservice?

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
       
        'Dim mydoc As xml
        Dim ds as New Dataset
        Dim ws As New citi.myXML ** web reference class "citi" parameter myXML !!! this is what I need to pass myXMLdoc to
        ' Dim myXML As
        ds.ReadXml("C:\ATC\SampleRequest1.xml")            ***LOAD IN XML DOC****
        ws.getOrders(ds)                                       ***send it back to web service as parameter*****
   
On the server side:

    Public Function getOrders(ByVal myDataSet As DataSET) As Xml.XmlDocument
        Dim myDoc As New Xml.XmlDocument
        myDataSet.WriteXML("E:\cxxxx2b\Temp.xml") 'Use any temporary path here
        myDoc.LoadXML("E:\cxxxx2b\Temp.xml")


Dabas
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
scubamikeyAuthor Commented:
Ding Ding Ding. Now I get It

Thank you

Scubamikey
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.