消费Soap服务,接收为对象,如何写为XML?

时间:2010-11-23 04:06:10

标签: c# xml soap

我是初级开发人员,并尝试编写一个使用SOAP Web服务的应用程序。

使用Web引用,我可以轻松调用Soap Web服务器的Web方法,但问题是 服务器返回一个对象(我认为是UBL XML对象)。我可以将其各个元素/节点作为XML对象访问。但是如果我想输出它对XML文件/对象的响应,我该怎么办呢?将对象输出为XML对象可能是一项微不足道的任务,但我不知道从哪里开始。我已经尝试过返回对象的简单调用ToString()不起作用。我是否需要通过http POST发送SOAP标头和正文以及解释/编写响应流以获得响应作为XML文本?

这是我用来检索UBL格式化XML对象的代码:

/// <summary>
/// Used by supplier to check Order
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnRequestPO_Click(object sender, EventArgs e)
{
    string t_return;
    SupplierServices supplierServices = new SupplierServices();

    LoginDetails lgDetails = new LoginDetails();
    lgDetails.UserName = "user";
    lgDetails.Password = "password";
    supplierServices.LoginDetailsValue = lgDetails;

    RequestPurchaseOrder requestPO = new RequestPurchaseOrder();
    requestPO.SupplierCode = "1234";
    try
    {
        Order returned_order = supplierServices.SupplierRequestPO(requestPO);
        if (returned_order != null)
        {
            //Simply call the ToString wouldn't work, it will return a
            //class name instead.
            t_return = returned_order.ToString();
            MessageBox.Show(t_return);
        }
        else
            MessageBox.Show("Returned order is empty!");
    }
    catch (Exception ex)
    {
        String responseFromServer = ex.Message.ToString() + " ";
        if (ex!= null)
        {
          MessageBox.Show(responseFromServer);
        }
    }  

这是我应该得到的SOAP响应:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <SupplierRequestPOResponse xmlns="https://extranet.thewarehouse.co.nz/ElectronicCommerce/">
      <Order xmlns="urn:oasis:names:specification:ubl:schema:xsd:Order-2">
        <ID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
        <CopyIndicator xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
        <IssueDate xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
        <Note xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
        <Note xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
        <DocumentCurrencyCode xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
        <CustomerReference xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
        <LineCountNumeric xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
        <ValidityPeriod xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
          <StartDate xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <EndDate xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <Description xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <Description xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
        </ValidityPeriod>
        <ValidityPeriod xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
          <StartDate xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <EndDate xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <Description xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <Description xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
        </ValidityPeriod>
        <BuyerCustomerParty xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
          <CustomerAssignedAccountID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <Party>
            <EndpointID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <PartyName xsi:nil="true" />
            <PartyName xsi:nil="true" />
            <PostalAddress xsi:nil="true" />
            <PhysicalLocation xsi:nil="true" />
            <PartyTaxScheme xsi:nil="true" />
            <PartyTaxScheme xsi:nil="true" />
          </Party>
          <BuyerContact>
            <ID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Name xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Telephone xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Telefax xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          </BuyerContact>
        </BuyerCustomerParty>
        <SellerSupplierParty xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
          <CustomerAssignedAccountID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <Party>
            <EndpointID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <PartyName xsi:nil="true" />
            <PartyName xsi:nil="true" />
            <PostalAddress xsi:nil="true" />
            <PhysicalLocation xsi:nil="true" />
            <PartyTaxScheme xsi:nil="true" />
            <PartyTaxScheme xsi:nil="true" />
          </Party>
        </SellerSupplierParty>
        <ManufacturerParty xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
          <EndpointID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <PartyName>
            <Name xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          </PartyName>
          <PartyName>
            <Name xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          </PartyName>
          <PostalAddress>
            <StreetName xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <AdditionalStreetName xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <CitySubdivisionName xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <CityName xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Country xsi:nil="true" />
          </PostalAddress>
          <PhysicalLocation>
            <Address xsi:nil="true" />
          </PhysicalLocation>
          <PartyTaxScheme>
            <RegistrationName xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <CompanyID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <TaxScheme xsi:nil="true" />
          </PartyTaxScheme>
          <PartyTaxScheme>
            <RegistrationName xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <CompanyID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <TaxScheme xsi:nil="true" />
          </PartyTaxScheme>
        </ManufacturerParty>
        <Delivery xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
          <Quantity xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <TrackingID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <DeliveryParty>
            <EndpointID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <PartyName xsi:nil="true" />
            <PartyName xsi:nil="true" />
            <PostalAddress xsi:nil="true" />
            <PhysicalLocation xsi:nil="true" />
            <PartyTaxScheme xsi:nil="true" />
            <PartyTaxScheme xsi:nil="true" />
          </DeliveryParty>
        </Delivery>
        <Delivery xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
          <Quantity xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <TrackingID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <DeliveryParty>
            <EndpointID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <PartyName xsi:nil="true" />
            <PartyName xsi:nil="true" />
            <PostalAddress xsi:nil="true" />
            <PhysicalLocation xsi:nil="true" />
            <PartyTaxScheme xsi:nil="true" />
            <PartyTaxScheme xsi:nil="true" />
          </DeliveryParty>
        </Delivery>
        <TransactionConditions xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
          <ID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <ActionCode xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <Description xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <Description xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <DocumentReference>
            <ID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <CopyIndicator xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <UUID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <IssueDate xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <DocumentTypeCode xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <DocumentType xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <XPath xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <XPath xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Attachment xsi:nil="true" />
          </DocumentReference>
          <DocumentReference>
            <ID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <CopyIndicator xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <UUID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <IssueDate xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <DocumentTypeCode xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <DocumentType xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <XPath xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <XPath xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Attachment xsi:nil="true" />
          </DocumentReference>
        </TransactionConditions>
        <TaxTotal xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
          <TaxAmount xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
        </TaxTotal>
        <TaxTotal xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
          <TaxAmount xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
        </TaxTotal>
        <AnticipatedMonetaryTotal xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
          <LineExtensionAmount xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <AllowanceTotalAmount xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <PayableAmount xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
        </AnticipatedMonetaryTotal>
        <OrderLine xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
          <Note xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <LineItem>
            <ID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Note xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <LineStatusCode xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Quantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <LineExtensionAmount xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <TotalTaxAmount xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <MinimumQuantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <MaximumBackorderQuantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <PartialDeliveryIndicator xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <BackOrderAllowedIndicator xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Delivery xsi:nil="true" />
            <Delivery xsi:nil="true" />
            <PricingReference xsi:nil="true" />
            <Price xsi:nil="true" />
            <Item xsi:nil="true" />
          </LineItem>
          <BuyerProposedSubstituteLineItem>
            <ID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Note xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <LineStatusCode xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Quantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <LineExtensionAmount xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <TotalTaxAmount xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <MinimumQuantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <MaximumBackorderQuantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <PartialDeliveryIndicator xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <BackOrderAllowedIndicator xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Delivery xsi:nil="true" />
            <Delivery xsi:nil="true" />
            <PricingReference xsi:nil="true" />
            <Price xsi:nil="true" />
            <Item xsi:nil="true" />
          </BuyerProposedSubstituteLineItem>
          <BuyerProposedSubstituteLineItem>
            <ID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Note xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <LineStatusCode xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Quantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <LineExtensionAmount xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <TotalTaxAmount xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <MinimumQuantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <MaximumBackorderQuantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <PartialDeliveryIndicator xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <BackOrderAllowedIndicator xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Delivery xsi:nil="true" />
            <Delivery xsi:nil="true" />
            <PricingReference xsi:nil="true" />
            <Price xsi:nil="true" />
            <Item xsi:nil="true" />
          </BuyerProposedSubstituteLineItem>
        </OrderLine>
        <OrderLine xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
          <Note xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
          <LineItem>
            <ID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Note xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <LineStatusCode xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Quantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <LineExtensionAmount xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <TotalTaxAmount xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <MinimumQuantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <MaximumBackorderQuantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <PartialDeliveryIndicator xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <BackOrderAllowedIndicator xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Delivery xsi:nil="true" />
            <Delivery xsi:nil="true" />
            <PricingReference xsi:nil="true" />
            <Price xsi:nil="true" />
            <Item xsi:nil="true" />
          </LineItem>
          <BuyerProposedSubstituteLineItem>
            <ID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Note xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <LineStatusCode xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Quantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <LineExtensionAmount xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <TotalTaxAmount xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <MinimumQuantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <MaximumBackorderQuantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <PartialDeliveryIndicator xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <BackOrderAllowedIndicator xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Delivery xsi:nil="true" />
            <Delivery xsi:nil="true" />
            <PricingReference xsi:nil="true" />
            <Price xsi:nil="true" />
            <Item xsi:nil="true" />
          </BuyerProposedSubstituteLineItem>
          <BuyerProposedSubstituteLineItem>
            <ID xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Note xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <LineStatusCode xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Quantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <LineExtensionAmount xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <TotalTaxAmount xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <MinimumQuantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <MaximumBackorderQuantity xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <PartialDeliveryIndicator xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <BackOrderAllowedIndicator xsi:nil="true" xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
            <Delivery xsi:nil="true" />
            <Delivery xsi:nil="true" />
            <PricingReference xsi:nil="true" />
            <Price xsi:nil="true" />
            <Item xsi:nil="true" />
          </BuyerProposedSubstituteLineItem>
        </OrderLine>
      </Order>
    </SupplierRequestPOResponse>
  </soap:Body>
</soap:Envelope>

2 个答案:

答案 0 :(得分:0)

您可以使用XmlSerializer:

public static string Serialize(object input)
{
    if (input == null)
        return null;

    System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(input.GetType());

    using (MemoryStream ms = new MemoryStream())
    using (StreamReader sr = new StreamReader(ms))
    {
        ser.Serialize(ms, input);
        ms.Seek(0, 0);
        return sr.ReadToEnd();
    }
}

并像这样传递returned_order

MessageBox.Show(Serialize(returned_order));

答案 1 :(得分:0)

Mark Avenius提供了一个如何将任何对象转换为XML的好例子。如果这就是你要做的一切,他的回答将完全符合你的需求。

但是,听起来好像您正在尝试验证SOAP响应本身 - XmlSerializer不允许您这样做。相反,它正在将一个对象转换为它自己的想法,即XML中的对象应该是什么样的,而不是通过网络接收的内容。

如果您实际上是在尝试验证SOAP响应,我建议您使用精彩的工具Fiddler。它允许您手工制作任何类型的Web请求,包括SOAP,并分析收到的确切响应。它对于.NET Web开发非常有用。