使用ASP.Net中的Web服务,无法正常工作

时间:2019-05-21 08:29:43

标签: c# asp.net soap asmx

我正在寻找一个可以使用附加请求的Web服务ASP.Net(C#)解决方案,由于标头记录,它必须在后面的代码中完成:

POST http://training.maxmoney.co.za/MaxAdmin/web_services/maxmoney/ HTTP/1.1
SOAPAction: http://training.maxmoney.co.za/MaxAdmin/web_services/maxmoney/ConnectionTest
Username: albatross_soap
Password: @1B@tr0$$
Content-Type: text/xml;charset="utf-8"
Host: training.maxmoney.co.za
Content-Length: 1227
Expect: 100-continue
Connection: Keep-Alive

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:max="http://training.maxmoney.co.za/webservices/maxmoney.xsd">
   <soapenv:Header>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:UsernameToken wsu:Id="UsernameToken-E033FC91FFC6A82CA915397704062061">
                <wsse:Username>albatross_soap</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">@1B@tr0$$</wsse:Password>
                <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">gNpe7bc1ArfIL0A6pAvYUQ==</wsse:Nonce>
                <wsu:Created>2018-10-17T10:00:06.205Z</wsu:Created>
            </wsse:UsernameToken>
        </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <max:connectionTest>
         <iGIDCode>910821</iGIDCode>
         <iMleAPIKey>4QWPiKbK4k7kvSuRAu1vrr2Mtxs</iMleAPIKey>
         <iCustomID/>
         <iCustomCode/>
      </max:connectionTest>
   </soapenv:Body>
</soapenv:Envelope>

回复是:

  

ReplyCode(4个字符)(0000-成功)

     

ReplyStr(日期和时间)

我尝试通过以下方式使用它:

string xml = doc.ToString();
string url = "http://training.maxmoney.co.za/MaxAdmin/web_services/maxmoney/";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(xml);
req.Method = "POST";
req.ContentType = "text/xml;charset=utf-8";
req.ContentLength = requestBytes.Length;
Stream requestStream = req.GetRequestStream();
requestStream.Write(requestBytes, 0, requestBytes.Length);
requestStream.Close();

HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
string backstr = sr.ReadToEnd();

HttpContext.Current.Response.Write(backstr);
sr.Close();
res.Close();

但是我得到文件不存在错误, 回复代码必须为:

  

回复代码:0000

     

ReplyStr :(当前日期时间)

0 个答案:

没有答案