sending an xml file over a web service

J

Jon

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
 
J

John Saunders

Jon said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top