sending an xml file over a web service

Discussion in 'ASP .Net Web Services' started by Jon, Nov 17, 2006.

  1. Jon

    Jon Guest

    My boss has told a customer of ours that they can call method on our web
    service and send us an xml file that we will then pull data from and do
    stuff with.

    I worked briefly with web services in .Net 1.1, but never did much beyond
    the basics.

    We are now working in .Net 2.0 and I'm wondering the best way to accomplish
    what he's told the customer. Should I have the web service has an input
    method with a string variable and just have our customer suck their xml file
    into a string and pass it over to our webmethod, and then constitute an xml
    document from the passed-in string? Or is there a better way someone can
    thing of?

    Thanks
    Jon
    Jon, Nov 17, 2006
    #1
    1. Advertising

  2. "Jon" <> wrote in message
    news:...
    > My boss has told a customer of ours that they can call method on our web
    > service and send us an xml file that we will then pull data from and do
    > stuff with.
    >
    > I worked briefly with web services in .Net 1.1, but never did much beyond
    > the basics.
    >
    > We are now working in .Net 2.0 and I'm wondering the best way to
    > accomplish what he's told the customer. Should I have the web service has
    > an input method with a string variable and just have our customer suck
    > their xml file into a string and pass it over to our webmethod, and then
    > constitute an xml document from the passed-in string? Or is there a better
    > way someone can thing of?


    You can define your parameter as xsd:any. Here's the definition of the
    content of a Ping request and response which allows any content to be sent
    to the service and sends it back in the response:

    <xs:complexType name="PingContents">
    <xs:sequence>
    <xs:any namespace="##any" processContents="skip" minOccurs="0"
    maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:anyAttribute namespace="##any" processContents="skip"/>
    </xs:complexType>

    <xs:element name="pingRequest" type="tns:pingContents"/>
    <xs:element name="pingResponse" type="tns:pingContents"/>

    In the WSDL:

    <wsdl:message name="pingRequestMessage">
    <wsdl:part element="msg:pingRequest" name="parameter"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="pingResponseMessage">
    <wsdl:part element="msg:pingResponse" name="response"></wsdl:part>
    </wsdl:message>

    The server stub:

    [WebMethod(),
    SoapDocumentMethod("urn:dontCare", Use=SoapBindingUse.Literal,
    ParameterStyle=SoapParameterStyle.Bare)]
    [return : XmlElement("pingResponse",Namespace="urn:messageTypes.urn.com")]
    public abstract PingContents
    Ping([XmlElement(Namespace="urn:messageTypes.urn.com")] PingContents
    pingRequest);

    The implementation:

    PingContents response = new PingContents();
    response.AnyAttr = new XmlAttribute[pingRequest.Attributes.Count];
    pingRequest.Attributes.CopyTo(response.AnyAttr, 0);
    int elementCount = 0;
    for (int i = 0; i < pingRequest.ChildNodes.Count; i++)
    {
    if (pingRequest.ChildNodes.NodeType == XmlNodeType.Element)
    {
    elementCount++;
    }
    }

    if (elementCount > 0)
    {
    response.Any = new XmlElement[elementCount];
    int j = 0;
    for (int i = 0; i < pingRequest.ChildNodes.Count; i++)
    {
    if (pingRequest.ChildNodes.NodeType == XmlNodeType.Element)
    {
    response.Any[j++] = (XmlElement) pingRequest.ChildNodes;
    }
    }
    }

    return response;


    I hope that helps.

    John
    John Saunders, Nov 18, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    676
  2. Jonathan Woods

    Sending data over internet using web service

    Jonathan Woods, Apr 29, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    524
    Laurent Bugnion
    Apr 29, 2006
  3. Digital Puer
    Replies:
    1
    Views:
    847
    Dag Sunde
    Jun 1, 2006
  4. Hidura
    Replies:
    6
    Views:
    1,090
    John Nagle
    Dec 22, 2010
  5. Levi Nie
    Replies:
    1
    Views:
    144
    Ulrich Eckhardt
    Jan 15, 2013
Loading...

Share This Page