在Soap XML信封中发送“ XML数据作为字符串”

卡雷尔

我有需要接收XML字符串的WCF Soap Web服务。尽管我对Web服务的经验很少,但我已经提出了这个建议。应该从SAP PI调用此Web服务。

请求消息的结构如下:

public class DtoRequest<T> : IDtoRequest where T : class
{
    public InteractionContext Context { get; set; }
    public T Request { get; set; }
}

其中类型是以下类

public class SendRfqRequest : DtoRequest<ImportRfqDataDto>
{
}

[DataContract]
public class ImportRfqDataDto
{
    [DataMember]
    public string RfqXmlData { get; set; }
}

InteractionContext包含以下字段:

public class InteractionContext
{
    public string Application { get; set; }
    public string License { get; set; }
    public DateTime TimeStamp { get; set; }
    public Guid Id { get; set; }
}

我将其部署在webservicesdev服务器上,生成了将其与wsdl.exe结合使用的代码,并通过一个简单的控制台应用程序对其进行了测试:

// Generated from wsdl.exe tool
RfqImportServiceClient client = new RfqImportServiceClient();
// Xml Document
XDocument rfqXml = XDocument.Load("..\\..\\RfqValidGood.xml");

SendRfqRequest request = new SendRfqRequest
{
    Context = new CityOfCapeTown.Services.Common.InteractionContext
    {
        Id = Guid.NewGuid(),
        Application = "TestApplication",
        License = "TestLicenseKey",
        TimeStamp = DateTime.Now,
    },
    Request = new DataTransferObjects.ImportRfqDataDto
    {
        RfqXmlData = rfqXml.ToString()
    }
};

Console.WriteLine("\n\n- Attempting connection to web-service");
SendRfqResponse response = client.ProcessRfq(request);
Console.WriteLine("- Successfully connected to web-service");
Console.WriteLine("- Status of response: " + (ResponseType)response.Result);

所有这一切都完美。从SAP PI测试Web服务时出现问题。在RfqXmlData标记中传递XML数据时出现问题。我尝试在SOAP UI中对其进行测试。它从wsdl生成了以下SOAP信封:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:cit="http://schemas.datacontract.org/2004/07/CityOfCapeTown.Services.Common" xmlns:proc="http://schemas.datacontract.org/2004/07/ProcurementAdministrationPortal.WebService.DataTransferObjects">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:ProcessRfq>
         <!--Optional:-->
         <tem:request>
            <!--Optional:-->
            <cit:Context>
               <!--Optional:-->
               <cit:Application>SAPClient</cit:Application>
               <!--Optional:-->
               <cit:Id>1a975cab-bc7c-47e3-aa77-ac9dc407721d</cit:Id>
               <!--Optional:-->
               <cit:License>1a975cab-bc7c-47e3-aa77-ac9dc407721d</cit:License>
               <!--Optional:-->
               <cit:TimeStamp>2014-01-01</cit:TimeStamp>
            </cit:Context>
            <!--Optional:-->
            <cit:Request>
               <!--Optional:-->
               <proc:RfqXmlData>
                xmldata
               </proc:RfqXmlData>
            </cit:Request>
         </tem:request>
      </tem:ProcessRfq>
   </soapenv:Body>
</soapenv:Envelope>

在标记中传递一些随机字符串时,这在SOAP UI中有效:

<proc:RfqXmlData>
    random string
</proc:RfqXmlData>

但是在传递所需的XML数据时出现错误:

<proc:RfqXmlData>
    <Rfq><IsAbove30k>true</IsAbove30k><ReferenceNumber>ReferenceNumber1</ReferenceNumber><ContactPersonName>ContactPersonName1</ContactPersonName><ContactPersonTelephoneNumber>ContactPersonTe1</ContactPersonTelephoneNumber><ContactPersonCellPhone>ContactPersonCe1</ContactPersonCellPhone><BuyerName>BuyerName1</BuyerName><BuyerTelephoneNumber>BuyerTelephoneN111111111111111111111</BuyerTelephoneNumber><BuyerEmailAddress>BuyerEmailAddress1</BuyerEmailAddress><ProcurementItem><Title>Title111111111111111111111111</Title><ClosingDate>1900-01-01T01:01:01+02:00</ClosingDate><Description>Description11111111111111111</Description><CaptureDate>1900-01-01T01:01:01+02:00</CaptureDate></ProcurementItem><RfqGood><DeliveryTo>DeliveryTo1</DeliveryTo><DeliveryAddress>DeliveryAddress1</DeliveryAddress><DeliverySuburb>DeliverySuburb1</DeliverySuburb><DeliveryPostalCode>1</DeliveryPostalCode><SubmissionFax>SubmissionFax1</SubmissionFax><Specification>Specification1</Specification><SubmissionFax2>SubmissionFax21</SubmissionFax2><DeliveryDate>1900-01-01T01:01:01+02:00</DeliveryDate><Good>Tools &amp; Machinery</Good></RfqGood></Rfq>
</proc:RfqXmlData>

错误:

<faultstring xml:lang="en-ZA">The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:request. The InnerException message was 'There was an error deserializing the object of type ProcurementAdministrationPortal.WebService.Messages.SendRfqRequest. End element 'RfqXmlData' from namespace 'http://schemas.datacontract.org/2004/07/ProcurementAdministrationPortal.WebService.DataTransferObjects' expected. Found element 'Rfq' from namespace ''. Line 22, position 10.'.  Please see InnerException for more details.</faultstring>

似乎在试图反序列化<Rfq>...</Rfq>在我看来,我必须做的就是获得将XML数据视为字符串而不是XML的服务。但是,我仍然需要它在另一端是XML。

卡雷尔

将一段XML包装在一个<![CDATA[]]>标签中。

CDATA代表字符数据,这意味着这些标签之间的数据包括可以解释为XML标记的数据,但不应如此。”

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章