![]() |
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 |
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.