使用C sharp的POST xsd架构与XML POST类似吗? [英] POST xsd schema using C sharp is it similar like XML POST?

查看:85
本文介绍了使用C sharp的POST xsd架构与XML POST类似吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用c sharp发布了xml下面给出的代码,但如果我必须发布xsd架构那样



http://webservices.travelpack.com/xsd/external/FlightChoice.xsd [ ^ ]





这里是我想要发布的内容所以请告诉我如何发布XSD SCHEMA是否类似于XML POST?



i have posted xml using c sharp the code given below but what if i have to post xsd schema like that

http://webservices.travelpack.com/xsd/external/FlightChoice.xsd[^]


here is its content that i want to post SO KINDLY TELL ME HOW TO POST XSD SCHEMA IS IT SIMILAR LIKE XML POST?

<xs:complexType>
 <xs:sequence>
  <xs:element type="Source" name="Source"/>
   <xs:element type="AgentId" name="AgentId" minOccurs="0"/>
   <xs:element type="Password" name="Password" minOccurs="0"/>
   <xs:element type="SessionId" name="SessionId"/>
   <xs:element type="ClearBasket" name="ClearBasket" minOccurs="0"/>
   <xs:element type="ItemReference" name="ItemRef"/>
   <xs:element type="Item" name="OutAvail"/>
  <xs:element type="Item" name="InbAvail" minOccurs="0"/>
 </xs:sequence>
</xs:complexType>







我发布的是






and what i have posted is that

<Request>
   <FlightSearch>
   <Source>0</Source>
   <AgentId>0</AgentId>
   <Password>0=</Password>
    <From>lhr</From>
    <To>lhe</To>
    <RetFrom />
    <RetTo />
    <Journey>R</Journey>
    <Direct />
    <Availability>O</Availability>
   </FlightSearch>
 </Request>





我的尝试:





What I have tried:

  public string postXMLData(string destinationUrl, XDocument requestXml)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(destinationUrl);
            byte[] bytes;
            bytes = Encoding.UTF8.GetBytes(requestXml.ToString());
            request.ContentType = "text/xml";
            request.ContentLength = bytes.Length;
            request.Method = "POST";
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(bytes, 0, bytes.Length);
            requestStream.Close();
            HttpWebResponse response;
            response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
            {
                Stream responseStream = response.GetResponseStream();
                string responseStr = new StreamReader(responseStream).ReadToEnd();
             }

         }

推荐答案

XML模式(XSD)按定义是XML文件,因此您可以像处理包含数据元素的常规XML文件一样处理它。

请参阅 XML Schema Tutorial [ ^ ]



您可能想告诉接收者您正在发送架构而不是内容。

您可以使用例如整数来执行此操作值1表示内容,2表示架构,或者适合您的需要。



当然可以自动检测它是什么类型的文件,但它通常最好清楚你要发送什么。

如果你不能改变通信协议,自动检测可能是一个选项。
An XML schema (XSD) IS an XML file by definition, so you can treat it in the same way as a regular XML file containing data elements.
See XML Schema Tutorial[^]

You might want to tell the receiver that you are sending a schema instead of content.
You can do this with, for example, an integer where the value 1 means content and 2 means schema, or what ever suits your needs.

It is of course possible to auto detect what kind of file it is, but it is usually better to be clear about what you are sending.
Auto detection could be an option if you can't change the communication protocol.


这篇关于使用C sharp的POST xsd架构与XML POST类似吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆