【问题标题】:XML validation error when converting SOAPSonar to C#将 SOAPSonar 转换为 C# 时出现 XML 验证错误
【发布时间】:2018-06-20 14:40:55
【问题描述】:

我可以在 SOAPSonar 中毫无问题地运行以下 SOAP 请求(通过 WSDL 生成),并且我可以取回数据:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ng1="http://www.sx3.com/GET_PERSON_DETAILS">
  <soap:Body>
    <ng1:ParDetailsRequest>
      <ng1:ParRefno>1200</ng1:ParRefno>
      <ng1:FormerNameChkInd>Y</ng1:FormerNameChkInd>
      <ng1:RacPay>REVENUE ACCOUNT</ng1:RacPay>
      <ng1:CurrentParInd>Y</ng1:CurrentParInd>
      <ng1:CurrentAppInd>A</ng1:CurrentAppInd>
      <ng1:CurrentTcyInd>A</ng1:CurrentTcyInd>
      <ng1:RtnContactAddrInd>Y</ng1:RtnContactAddrInd>
      <ng1:RtnContactDetailsInd>N</ng1:RtnContactDetailsInd>
      <ng1:RtnAusInd>Y</ng1:RtnAusInd>
      <ng1:RtnAppInd>Y</ng1:RtnAppInd>
      <ng1:RtnTcyInd>Y</ng1:RtnTcyInd>
      <ng1:RtnOtherFieldsInd>N</ng1:RtnOtherFieldsInd>
      <ng1:RtnFmrNameHistInd>Y</ng1:RtnFmrNameHistInd>
      <ng1:RtnNotepadsInd>N</ng1:RtnNotepadsInd>
    </ng1:ParDetailsRequest>
  </soap:Body>
</soap:Envelope>

我尝试用 C# 实现请求如下(基于this answer):

public static String CallWebService(String URL, int RefNum)
{

    XmlDocument Envelope = CreateEnvelope(RefNum);
    HttpWebRequest Request = CreateRequest(URL);
    InsertEnvelope(Request, Envelope);

    IAsyncResult AsyncResult = Request.BeginGetResponse(null, null);
    AsyncResult.AsyncWaitHandle.WaitOne();

    String Result;

    using (WebResponse Response = Request.EndGetResponse(AsyncResult))
    {
        using (StreamReader Reader = new StreamReader(Response.GetResponseStream())) Result = Reader.ReadToEnd();
    }

    return Result;

}

private static XmlDocument CreateEnvelope(int RefNum)
{

    XmlDocument Envelope = new XmlDocument();

    Envelope.LoadXml(
        String.Format(@"
            <soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:ng1=""http://www.sx3.com/GET_PERSON_DETAILS"">
                <soap:Body>
                    <ng1:ParDetailsRequest>
                        <ng1:ParRefno>{0}</ng1:ParRefno>
                        <ng1:FormerNameChkInd>Y</ng1:FormerNameChkInd>
                        <ng1:RacPay>REVENUE ACCOUNT</ng1:RacPay>
                        <ng1:CurrentParInd>Y</ng1:CurrentParInd>
                        <ng1:CurrentAppInd>A</ng1:CurrentAppInd>
                        <ng1:CurrentTcyInd>A</ng1:CurrentTcyInd>
                        <ng1:RtnContactAddrInd>Y</ng1:RtnContactAddrInd>
                        <ng1:RtnContactDetailsInd>Y</ng1:RtnContactDetailsInd>
                        <ng1:RtnAusInd>Y</ng1:RtnAusInd>
                        <ng1:RtnAppInd>Y</ng1:RtnAppInd>
                        <ng1:RtnTcyInd>Y</ng1:RtnTcyInd>
                        <ng1:RtnOtherFieldsInd>N</ng1:RtnOtherFieldsInd>
                        <ng1:RtnFmrNameHistInd>Y</ng1:RtnFmrNameHistInd>
                        <ng1:RtnNotepadsInd>N</ng1:RtnNotepadsInd>
                    </ng1:ParDetailsRequest>
                </soap:Body>
            </soap:Envelope>
        ", RefNum.ToString())
    );

    return Envelope;

}

private static HttpWebRequest CreateRequest(String URL)
{

    HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(URL);
    //Request.Headers.Add(@"SOAP:Action");
    Request.ContentType = "text/xml;charset=\"utf-8\"";
    Request.Accept = "text/xml";
    Request.Method = "POST";
    return Request;

}

private static void InsertEnvelope(HttpWebRequest Request, XmlDocument Envelope)
{
    using (Stream Stream = Request.GetRequestStream()) Envelope.Save(Stream);
}

但我收到以下错误响应:

  • ORA-31043:元素“信封”未在架构中全局定义 'GET_PERSON_DETAILS.xsd'
  • 提供的 XML 验证失败。联系支持。

【问题讨论】:

    标签: c# .net xml soap wsdl


    【解决方案1】:

    这里的问题在于 SOAPAction 标头。 我从这里改变了它:

    Request.Headers.Add(@"SOAP:Action");
    

    到这里:

    Request.Headers.Add("SOAPAction", (URL + "gateway"));
    

    【讨论】:

      猜你喜欢
      • 2016-12-18
      • 1970-01-01
      • 2016-01-04
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      • 2014-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多