?
Solved

Web service that accepts on XML Doc as input parameter

Posted on 2004-11-20
13
Medium Priority
?
261 Views
Last Modified: 2010-04-24
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
0
Comment
Question by:scubamikey
  • 7
  • 6
13 Comments
 
LVL 27

Expert Comment

by:Dabas
ID: 12635984
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
 

Author Comment

by:scubamikey
ID: 12636006
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
 
LVL 27

Expert Comment

by:Dabas
ID: 12636033
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:scubamikey
ID: 12636064
I Will try this & update you on the results.
Thanks
SM
0
 

Author Comment

by:scubamikey
ID: 12636208
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
 
LVL 27

Expert Comment

by:Dabas
ID: 12636232
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
 

Author Comment

by:scubamikey
ID: 12636649
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
 
LVL 27

Expert Comment

by:Dabas
ID: 12640102
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
 

Author Comment

by:scubamikey
ID: 12640674
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
 
LVL 27

Expert Comment

by:Dabas
ID: 12640688
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
 

Author Comment

by:scubamikey
ID: 12641133
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
 
LVL 27

Accepted Solution

by:
Dabas earned 1600 total points
ID: 12641181
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
 

Author Comment

by:scubamikey
ID: 12641196
Ding Ding Ding. Now I get It

Thank you

Scubamikey
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question