使用 HTTP/1.0 的网络服务 HTTP 请求

Webservice HTTP request using HTTP/1.0

我正在使用 C# 向合作伙伴网络服务发送 SOAP 请求,

public class EODReproting : System.Web.Services.WebService
{
    /// <summary>
    /// Execute a Soap WebService call
    /// </summary>
    [WebMethod(MessageName = "SendZRARequest")]
    public void Execute()
    {
            HttpWebRequest request = CreateWebRequest();
            XmlDocument soapEnvelopeXml = new XmlDocument();
            soapEnvelopeXml.LoadXml(@"
                <soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ser=""http://service.bank.pmt.zra"" xmlns:xsd=""   http://bean.bank.pmt.zra/xsd"">
                <soapenv:Header/>
                <soapenv:Body>
                <ser:processPaymentNotificationReport>
                <!--Zero or more repetitions:-->
                <ser:pmtNotifyReport>
                <!--Optional:-->
                <xsd:amountPaid>XXXX</xsd:amountPaid>
                <!--Optional:-->
                <xsd:bankBranchCode>XXXXX</xsd:bankBranchCode>
                <!--Optional:-->
                <xsd:bankTransNo>XXXXX</xsd:bankTransNo>
                <!--Optional:-->
                <xsd:datePaid>XXXXXX</xsd:datePaid>
                <!--Optional:-->
                <xsd:paymentRegTransNo>XXXXXX</xsd:paymentRegTransNo>
                <!--Optional:-->
                <xsd:status>S</xsd:status>
                <!--Optional:-->
                <xsd:taxPayerName>BYAN MARTIN</xsd:taxPayerName>
                <!--Optional:-->
                <xsd:tin>1002760252</xsd:tin>
                <!--Optional:-->
            <xsd:transactionId>XXXXXXX</xsd:transactionId>
            </ser:pmtNotifyReport>
        </ser:processPaymentNotificationReport>
    </soapenv:Body>
</soapenv:Envelope>");


            using (Stream stream = request.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }

            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                {
                    string soapResult = rd.ReadToEnd();
                }
            }

        }

    }                    

    /// <summary>
    /// Create a soap webrequest to [Url]
    /// </summary>
    /// <returns></returns>
    public HttpWebRequest CreateWebRequest()
    {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://XX.XX.XX.XX:9999/ZraWebService/services/EODPaymentNotificationReportService.EODPaymentNotificationReportServiceHttpSoap11Endpoint/");
            webRequest.Headers.Add("SOAPAction", "urn:processPaymentNotificationReport");
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";
            webRequest.Proxy = null;

        return webRequest;
    }
  }
}

调用此方法时,我的日志文件夹中记录了一个错误,

2015.01.09 10:20:25.8485->The remote server returned an error: (500) Internal Server Error.   at      System.Net.HttpWebRequest.GetResponse()
at EODReporting.ZRAEODReproting.Execute()

合作伙伴告诉我使用HTTP/1.0发送请求,我想在上面的代码中这样做。我该怎么做?

只需在 HttpWebRequest 声明后添加以下选项:

request.ProtocolVersion=HttpVersion.Version10;