Soap Sending Handled Manually - XmlNode: NodeTypes and Attributes read only
I have to make a call to a webservice but building the xml manually. I've chosen System.Xml to do this but it's causing me a lot of pain.
Every SOAP I know consts of 3 parts:
- The XmlDeclaration
- The Header of the envelope or SOAP-ENV:Envelope
- The Body of the envelope or SOAP-ENV:Body
The thing is my XmlDocument only can contain one root element. (Don't know why) If I do
MyXMLDoc.CreateNode(XmlNodeType.DocumentFragment, "SOAP-ENV", "Envelope", "http://tempuri.org");
It does not let me append attributes. It says those are read only.
RESUMING:
How do I have to do to write this but without the root and with an XmlDeclaration? and how do I call a webservice (with this xml)?
-<root>
<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" />
- <SOAP-ENV:Body>
- <ZbcInsertRequest xmlns:ns1="'urn:sap-com:document:sap:soap:functions:mc-style'">
<Destino>qas</Destino>
- <IClrQst>
<Request>foo</Request>
<Proyecto>foofoo</Proyecto>
<Modulocq />
<Titureq>foofoofoo</Titureq>
<Tiporeq />
<Prioridad>0</Prioridad>
<Clasific />
<Asignadoa>foofoofoofoo</Asignadoa>
<Destino>qas</Destino>
<Solicita>foo</Solicita>
<Autoriza>c.foo</Autoriza>
<ModTransp />
<ReqSox>F</ReqSox>
<Notfylst />
<Tipodeploy>Normal</Tipodeploy>
<Paqdeploy>CDVQA00000000</Paqdeploy>
</IClrQst>
- <TRequest>
- <item>
<Trkorr>DESK9A0ZJT</Trkorr>
<Secuencia>0</Secuencia>
<Solicita>c.foo</Solicita>
<Type />
<Id />
<Numero />
<Message />
</item>
</TRequest>
</ZbcInsertRequest>
</SOAP-ENV:Body>
</root>
Here's the wsdl i'm connecting to
<wsdl:definitions targetNamespace="urn:sap-com:document:sap:soap:functions:mc-style">
<wsdl:types>
<xsd:schema targetNamespace="urn:sap-com:document:sap:rfc:functions" elementFormDefault="unqualified" attributeFormDefault="qualified">
<xsd:simpleType name="char1">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="1"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char10">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="10"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char100">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="100"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char15">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="15"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char20">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="20"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char220">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="220"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char255">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="255"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char30">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="30"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char32">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="32"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char50">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="50"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="numeric3">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="3"/>
<xsd:pattern value="\d*"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="numeric6">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="6"/>
<xsd:pattern value="\d*"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
<xsd:schema targetNamespace="urn:sap-com:document:sap:soap:functions:mc-style" elementFormDefault="unqualified" attributeFormDefault="qualified">
<xsd:import namespace="urn:sap-com:document:sap:rfc:functions"/>
<xsd:simpleType name="char1">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="1"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char10">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="10"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char12">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="12"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char120">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="120"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char20">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="20"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char250">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="250"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char3">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="3"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char4">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="4"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char60">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="60"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="date">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="10"/>
<xsd:pattern value="\d\d\d\d-\d\d-\d\d"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="numeric5">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="5"/>
<xsd:pattern value="\d*"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="numeric6">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="6"/>
<xsd:pattern value="\d*"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="time">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="8"/>
<xsd:pattern value="\d\d:\d\d:\d\d"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="ZtyEE070">
<xsd:sequence>
<xsd:element name="Trkorr" type="tns:char20"/>
<xsd:element name="As4text" type="tns:char60"/>
<xsd:element name="Trfunction" type="n0:char1"/>
<xsd:element name="Trstatus" type="n0:char1"/>
<xsd:element name="Tarsystem" type="tns:char10"/>
<xsd:element name="Korrdev" type="tns:char4"/>
<xsd:element name="As4user" type="tns:char12"/>
<xsd:element name="As4date" type="tns:date"/>
<xsd:element name="As4time" type="tns:time"/>
<xsd:element name="Strkorr" type="tns:char20"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ZtyEE071">
<xsd:sequence>
<xsd:element name="Trkorr" type="n0:char20"/>
<xsd:element name="As4pos" type="tns:numeric6"/>
<xsd:element name="Pgmid" type="tns:char4"/>
<xsd:element name="Object" type="tns:char4"/>
<xsd:element name="Objname" type="tns:char120"/>
<xsd:element name="Objfunc" type="tns:char1"/>
<xsd:element name="Lockflag" type="tns:char1"/>
<xsd:element name="Gennum" type="tns:char3"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Zclrqstdat">
<xsd:sequence>
<xsd:element name="Request" type="n0:char15"/>
<xsd:element name="Proyecto" type="n0:char50"/>
<xsd:element name="Modulocq" type="tns:char250"/>
<xsd:element name="Titureq" type="tns:char250"/>
<xsd:element name="Tiporeq" type="n0:char30"/>
<xsd:element name="Prioridad" type="n0:char15"/>
<xsd:element name="Clasific" type="n0:char100"/>
<xsd:element name="Asignadoa" type="n0:char50"/>
<xsd:element name="Destino" type="n0:char10"/>
<xsd:element name="Solicita" type="n0:char50"/>
<xsd:element name="Autoriza" type="n0:char50"/>
<xsd:element name="Modtransp" type="n0:char1"/>
<xsd:element name="Reqsox" type="n0:char1"/>
<xsd:element name="Notfylst" type="n0:char255"/>
<xsd:element name="Tipodeploy" type="n0:char50"/>
<xsd:element name="Paqdeploy" type="n0:char15"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Zrequest">
<xsd:sequence>
<xsd:element name="Trkorr" type="n0:char20"/>
<xsd:element name="Secuencia" type="tns:numeric5"/>
<xsd:element name="Solicita" type="n0:char50"/>
<xsd:element name="Type" type="n0:char1"/>
<xsd:element name="Id" type="n0:char20"/>
<xsd:element name="Numero" type="n0:numeric3"/>
<xsd:element name="Message" type="n0:char220"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Bapiret2">
<xsd:sequence>
<xsd:element name="Type" type="n0:char1"/>
<xsd:element name="Id" type="n0:char20"/>
<xsd:element name="Number" type="n0:numeric3"/>
<xsd:element name="Message" type="n0:char220"/>
<xsd:element name="Logno" type="n0:char20"/>
<xsd:element name="Logmsgno" type="n0:numeric6"/>
<xsd:element name="Messagev1" type="n0:char50"/>
<xsd:element name="Messagev2" type="n0:char50"/>
<xsd:element name="Messagev3" type="n0:char50"/>
<xsd:element name="Messagev4" type="n0:char50"/>
<xsd:element name="Parameter" type="n0:char32"/>
<xsd:element name="Row" type="xsd:int"/>
<xsd:element name="Field" type="n0:char30"/>
<xsd:element name="System" type="n0:char10"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="TableOfztyEE070">
<xsd:sequence>
<xsd:element name="item" minOccurs="0" maxOccurs="unbounded" type="tns:ZtyEE070"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="TableOfztyEE071">
<xsd:sequence>
<xsd:element name="item" minOccurs="0" maxOccurs="unbounded" type="tns:ZtyEE071"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="TableOfzrequest">
<xsd:sequence>
<xsd:element name="item" minOccurs="0" maxOccurs="unbounded" type="tns:Zrequest"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="ZbcInsertRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Destino" type="n0:char32"/>
<xsd:element name="EtRequestHeader" minOccurs="0" type="tns:TableOfztyEE070"/>
<xsd:element name="EtRequestObj" minOccurs="0" type="tns:TableOfztyEE071"/>
<xsd:element name="IClrqst" type="tns:Zclrqstdat"/>
<xsd:element name="TRequest" type="tns:TableOfzrequest"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="ZbcInsertRequestResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="EtRequestHeader" minOccurs="0" type="tns:TableOfztyEE070"/>
<xsd:element name="EtRequestObj" minOccurs="0" type="tns:TableOfztyEE071"/>
<xsd:element name="Return" type="tns:Bapiret2"/>
<xsd:element name="TRequest" type="tns:TableOfzrequest"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="ZbcInsertRequestString">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="EtRequestHeader" minOccurs="0" type="tns:TableOfztyEE070"/>
<xsd:element name="EtRequestObj" minOccurs="0" type="tns:TableOfztyEE071"/>
<xsd:element name="Sdestino" type="xsd:string"/>
<xsd:element name="SiClrqst" type="xsd:string"/>
<xsd:element name="TRequest" type="tns:TableOfzrequest"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="ZbcInsertRequestStringResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="EtRequestHeader" type="tns:TableOfztyEE070"/>
<xsd:element name="EtRequestObj" type="tns:TableOfztyEE071"/>
<xsd:element name="Return" type="tns:Bapiret2"/>
<xsd:element name="TRequest" type="tns:TableOfzrequest"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<style/>
<wsdl:message name="ZbcInsertRequest">
<wsdl:part name="parameters" element="tns:ZbcInsertRequest"/>
</wsdl:message>
<wsdl:message name="ZbcInsertRequestResponse">
<wsdl:part name="parameters" element="tns:ZbcInsertRequestResponse"/>
</wsdl:message>
<wsdl:message name="ZbcInsertRequestString">
<wsdl:part name="parameters" element="tns:ZbcInsertRequestString"/>
</wsdl:message>
<wsdl:message name="ZbcInsertRequestStringResponse">
<wsdl:part name="parameters" element="tns:ZbcInsertRequestStringResponse"/>
</wsdl:message>
<sap:Feature name="design_0 " uri="http://www.sap.com/webas/630/soap/features/authentication/">
<sap:Property qname="n1:AuthenticationLevel">
<sap:Option value="n1:None"/>
</sap:Property>
</sap:Feature>
<wsdl:portType name="ZICQ">
<sap:useFeature feature="tns:design_0 "/>
<wsdl:operation name="ZbcInsertRequest">
<wsdl:input message="tns:ZbcInsertRequest"/>
<wsdl:output message="tns:ZbcInsertRequestResponse"/>
</wsdl:operation>
<wsdl:operation name="ZbcInsertRequestString">
<wsdl:input message="tns:ZbcInsertRequestString"/>
<wsdl:output message="tns:ZbcInsertRequestStringResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ZICQSoapBinding" type="tns:ZICQ">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ZbcInsertRequest">
<soap:operation soapAction=""/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body开发者_运维问答 use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="ZbcInsertRequestString">
<soap:operation soapAction=""/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ZICQService">
<wsdl:port name="ZICQSoapBinding" binding="tns:ZICQSoapBinding">
<soap:address location="http://hmxwasd1.hylsamex.com.mx:8000/sap/bc/srt/rfc/sap/ZICQ?sap-client=100"/>
</wsdl:port>
For your specific question: in a SOAP envelope the Body element needs to be a child of the Envelope. You can't have the envelope be an empty element and the body following it. The code below shows how to load a modified version of this document in a XmlDocument object.
public class StackOverflow_6157636_751090
{
public static void Test()
{
string xml = @" <SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
<SOAP-ENV:Body>
<ZbcInsertRequest xmlns:ns1=""urn:sap-com:document:sap:soap:functions:mc-style"">
<Destino>qas</Destino>
<IClrQst>
<Request>foo</Request>
<Proyecto>foofoo</Proyecto>
<Modulocq />
<Titureq>foofoofoo</Titureq>
<Tiporeq />
<Prioridad>0</Prioridad>
<Clasific />
<Asignadoa>foofoofoofoo</Asignadoa>
<Destino>qas</Destino>
<Solicita>foo</Solicita>
<Autoriza>c.foo</Autoriza>
<ModTransp />
<ReqSox>F</ReqSox>
<Notfylst />
<Tipodeploy>Normal</Tipodeploy>
<Paqdeploy>CDVQA00000000</Paqdeploy>
</IClrQst>
<TRequest>
<item>
<Trkorr>DESK9A0ZJT</Trkorr>
<Secuencia>0</Secuencia>
<Solicita>c.foo</Solicita>
<Type />
<Id />
<Numero />
<Message />
</item>
</TRequest>
</ZbcInsertRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
MemoryStream ms = new MemoryStream();
Encoding encoding = new UTF8Encoding(false);
XmlWriter w = XmlWriter.Create(ms, new XmlWriterSettings { Indent = true, OmitXmlDeclaration = false, Encoding = encoding, IndentChars = " " });
doc.Save(w);
w.Flush();
Console.WriteLine(encoding.GetString(ms.ToArray()));
}
}
Now, another option you can consider (if possible) is not to send the SOAP request "manually", but use some tool (such as WCF or some other SOAP library) to create a proxy which you can use to send requests to the service. That way your client can simply "call a method" and the stack will take care of creating the SOAP envelope for you.
精彩评论