C# 使用Soap服务,作为对象接收,如何作为XML编写?

C# 使用Soap服务,作为对象接收,如何作为XML编写?,c#,xml,soap,C#,Xml,Soap,我是一名初级开发人员,试图编写一个应用程序来使用SOAPWeb服务 使用web引用,我可以很容易地调用Soap web服务器的web方法,但问题是 我认为服务器返回一个对象UBLXML对象。我可以作为XML对象访问它的各个元素/节点。但是,如果我想将其响应输出到XML文件/对象,我该怎么做呢?将对象作为XML对象输出可能是一项很简单的任务,但我不确定从哪里开始。我已经尝试过对返回对象的字符串的简单调用将不起作用。我是否需要向下传递http POST发送的SOAP头和正文,并解释/写入响应流以获得

我是一名初级开发人员,试图编写一个应用程序来使用SOAPWeb服务

使用web引用,我可以很容易地调用Soap web服务器的web方法,但问题是 我认为服务器返回一个对象UBLXML对象。我可以作为XML对象访问它的各个元素/节点。但是,如果我想将其响应输出到XML文件/对象,我该怎么做呢?将对象作为XML对象输出可能是一项很简单的任务,但我不确定从哪里开始。我已经尝试过对返回对象的字符串的简单调用将不起作用。我是否需要向下传递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>

您可以使用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();
    }
}
并按如下方式传递您返回的订单:

MessageBox.Show(Serialize(returned_order));

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

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


如果您实际上正在尝试验证SOAP响应,我建议您使用这个奇妙的工具。它将允许您手工编写任何类型的web请求,包括SOAP,并分析收到的确切响应。它对于.NET web开发是非常宝贵的。

谢谢你,Ben,我还没有考虑验证SOAP响应。但既然你提到了,我会记住Fiddler,如果我们需要验证服务器的响应。谢谢你,Mark,序列化正是我需要的。但是由于某些原因,MessageBox.Show不会显示返回的序列化结果,可能是因为它的大小?因为生成的XML文件将是600Ks?我让它直接写入文本,如果我愿意,应该可以显示为RichText。是的,MessageBox可以显示的大小可能有限制,但我想指出的是,我提供的Serialize方法返回一个字符串,因此在这一点上,您可以随意使用它。很高兴我能帮忙。