我正在使用Web Api项目中的soap服务,它对于存根工作正常,但是当我更改实际服务的URL时,总会返回存根结果下面的示例soap服务结果是代码提及。
public HttpResponseMessage ReversalTransaction([FromBody] Reversal form)
{
try
{
form.TAG1= string.IsNullOrEmpty(form.TAG1) ? "" : form.TAG1;
form.TAG2 = string.IsNullOrEmpty(form.TAG2) ? "" : form.TAG2;
form.TAG3 = string.IsNullOrEmpty(form.TAG3) ? "" : form.TAG3;
//Calling CreateSOAPWebRequest method
HttpWebRequest request = CreateSOAPWebRequest();
request.Proxy = null;
XmlDocument SOAPReqBody = new XmlDocument();
//SOAP Body Request
SOAPReqBody.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:wsdl=""http://schemas.xmlsoap.org/wsdl/"" xmlns:rev=""http://tempuri.org/ReversalFTMsgSet"">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
<rev:ReversalStatusReq>
<PARTNER_ID>" + form.PARTNER_ID + @"</PARTNER_ID>
<USERNAME>" + form.USERNAME + @"</USERNAME>
<PASSWORD>" + form.PASSWORD + @"</PASSWORD>
<FT_IDENTIFIER>" + form.FT_IDENTIFIER + @"</FT_IDENTIFIER>
<TAG1>" + form.TAG1 + @"</TAG1>
<TAG2>" + form.TAG2 + @"</TAG2>
<TAG3>" + form.TAG3 + @"</TAG3>
</rev:ReversalStatusReq>
</soapenv:Body>
</soapenv:Envelope>");
using (Stream stream = request.GetRequestStream())
{
SOAPReqBody.Save(stream);
}
//Geting response from request
using (WebResponse Serviceres = request.GetResponse())
{
using (StreamReader rd = new StreamReader(Serviceres.GetResponseStream()))
{
//reading stream
var ServiceResult = rd.ReadToEnd();
//writting stream result on console
string unescapedString = Regex.Unescape(ServiceResult);
var json = Newtonsoft.Json.JsonConvert.SerializeObject(unescapedString);
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(json, Encoding.UTF8, "application/json");
return response;
// Console.WriteLine(ServiceResult);
//Console.ReadLine();
}
}
}
catch (Exception ex)
{
throw ex;
}
}
public HttpWebRequest CreateSOAPWebRequest()
{
string ServiceIp = System.Configuration.ConfigurationManager.AppSettings["ServiceIP"];
string MyProxyHostString = System.Configuration.ConfigurationManager.AppSettings["ProxyURL"];
int MyProxyPort = string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["ProxyPort"]) ? 0 : Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ProxyPort"]);
var Req = (HttpWebRequest)WebRequest.Create(@""+ServiceIp);
if (string.IsNullOrEmpty(MyProxyHostString))
{
Req.Proxy = null;
}
else
{
Req.Proxy = new WebProxy(MyProxyHostString, MyProxyPort);
}
Req.ContentType = "application/json; charset=utf-8";
Req.Method = "POST";
//SOAPAction
Req.Headers.Add(@"SOAPAction:http://tempuri.org/ReversalFTMsgSet");
//Content_type
Req.ContentType = "text/xml;charset=\"utf-8\"";
Req.Accept = "text/xml";
//HTTP method
Req.Method = "POST";
//return HttpWebRequest
return Req;
}
以上是我调用Soap服务并返回其响应的代码。我什至不知道为什么我更改了soap服务的URL也会得到相同的结果。我正在通过URL使用肥皂服务。