无法使用C#

时间:2017-12-13 07:40:30

标签: c# asp.net xml soap

我正在尝试使用以下代码从SAP链接获取数据。但是当尝试使用GetResponse()访问响应时,我收到了错误消息。请提出一个可能的解决方法或解释为什么我收到此错误。

 string url = System.Configuration.ConfigurationSettings.AppSettings["SAPurl"]; 
    WebRequest request = WebRequest.Create(url);
    request.Method = "POST";
    request.ContentType = "text/xml;charset=utf-8";
    string username = System.Configuration.ConfigurationSettings.AppSettings["SAPuserID"];
    string pw = System.Configuration.ConfigurationSettings.AppSettings["SAPpassword"];
    string svcCredentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes( username  + ":" + pw ));
    request.Headers.Add("Authorization", "Basic " + svcCredentials);
    //More lines of code added  
    System.IO.Stream aStream = request.GetRequestStream();
    StreamWriter aStreamWriter = new StreamWriter(aStream); 

    aStreamWriter.Write(xmlString); //xmlString is generated as the below xml
    WebResponse response = request.GetResponse(); // This line throws error

额外代码xmlString生成如下。我相信这是实际的400错误代码指向的地方。标签内的所有值都被确认为正确。

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
    <add:To>AAA</add:To>
    <add:Action>BBB</add:Action>
    </soapenv:Header>
    <soapenv:Body>
    <SAPRequest>
    <header>
    <applicationName>CCC</applicationName>
    <userId>DDD</userId>
    <password>EEE</password>
    <server>FFF</server>
    <client>GGG</client>
    <systemNumber>HHH</systemNumber>
    </header>
    <body>
    <interfaceName>III</interfaceName>
    <listOfSomething>
    <number>1000001</number>
    <number>2000001</number>
    <number>3000001</number>
    <number>4000001</number>
    </listOfSomething>
    </body>
    </SAPRequest>
    </soapenv:Body>
    </soapenv:Envelope>

错误如下。

  

远程服务器返回错误:(400)错误请求。

注意:这是以前正在运行的代码,但现在它无效。

1 个答案:

答案 0 :(得分:1)

如果此代码正常工作(并且已经过验证)并且您现在收到错误消息,表明它正在远程服务器上发生,那么,假设您无法控制远程服务器,则需要询问该服务器管理员指导。

服务器上发生错误。它可能是任何东西(瞬态blip /新部署的代码需要更改/服务器关闭) - 您需要询问更多详细信息。

相关问题