Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Services (http://www.velocityreviews.com/forums/f64-asp-net-web-services.html)
-   -   sending an xml file over a web service (http://www.velocityreviews.com/forums/t786732-sending-an-xml-file-over-a-web-service.html)

Jon 11-17-2006 09:04 PM

sending an xml file over a web service
 
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



John Saunders 11-18-2006 02:39 PM

Re: sending an xml file over a web service
 
"Jon" <rosenberg@mainstreams.com> wrote in message
news:uhkM2toCHHA.4892@TK2MSFTNGP04.phx.gbl...
> 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:messageTy pes.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[i].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[i].NodeType == XmlNodeType.Element)
{
response.Any[j++] = (XmlElement) pingRequest.ChildNodes[i];
}
}
}

return response;


I hope that helps.

John




All times are GMT. The time now is 12:31 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57