这就是我们的外发肥皂在代码背后的样子。 它给我一个错误HTTP 500 ..我无法控制该服务。只是客户端使用此Web服务 https://mn-its.dhs.state.mn.us/MnHieEligAdapterWebServiceImpl/spring-ws/EligibilityAdapterMITA
错误
ns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body><soapenv:Fault>
<faultcode>soapenv:Server</faultcode><faultstring>WSWS4117E: An attempt was made to add an SOAPEnvelope with a protocol of SOAP 1.2 Protocol to a
SOAPMessage with a protocol of SOAP 1.1 Protocol.</faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
我知道这不是在wcf中使用soap的最好方法..我的意思是将其附加到stringbuilder中,但请求涉及在Http头中发送cookie,credentails。这就是我们这样做的原因。
C#代码
StringBuilder SoapEnvelope = new StringBuilder();
SoapEnvelope.Append("<soap:Envelope ");
SoapEnvelope.Append("xmlns:soap=");
SoapEnvelope.Append("\"http://www.w3.org/2003/05/soap-envelope\"");
SoapEnvelope.Append(" xmlns:cor=");
SoapEnvelope.Append("\"http://www.caqh.org/SOAP/WSDL/CORERule2.2.0.xsd\">");
SoapEnvelope.Append(Environment.NewLine);
SoapEnvelope.Append("<soap:Header/>");
SoapEnvelope.Append(Environment.NewLine);
SoapEnvelope.Append("<soap:Body>");
SoapEnvelope.Append(Environment.NewLine);
SoapEnvelope.Append("<cor:COREEnvelopeRealTimeRequest>");
SoapEnvelope.Append(Environment.NewLine);
SoapEnvelope.Append("<PayloadType>X12_270_005010X279A1</PayloadType>");
SoapEnvelope.Append(Environment.NewLine);
SoapEnvelope.Append("<ProcessingMode>RealTime</ProcessingMode>");
SoapEnvelope.Append(Environment.NewLine);
SoapEnvelope.Append("<PayloadID>" + DateTime.Now.Ticks.ToString().Substring(10) + "</PayloadID>");
SoapEnvelope.Append(Environment.NewLine);
string Tdate = DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
SoapEnvelope.Append("<TimeStamp>" + Tdate + "</TimeStamp>");
SoapEnvelope.Append(Environment.NewLine);
SoapEnvelope.Append("<SenderID>" + PayerDetails.SenderID + "</SenderID>");
SoapEnvelope.Append(Environment.NewLine);
SoapEnvelope.Append("<ReceiverID>" + PayerDetails.ReceiverID + "</ReceiverID>");
SoapEnvelope.Append(Environment.NewLine);
SoapEnvelope.Append("<CORERuleVersion>2.2.0</CORERuleVersion>");
SoapEnvelope.Append(Environment.NewLine);
Query270 = Generate270(production, UseAlternateProvider);
SoapEnvelope.Append("<Payload>");
SoapEnvelope.Append(Query270);
SoapEnvelope.Append("</Payload>");
SoapEnvelope.Append(Environment.NewLine);
SoapEnvelope.Append("</cor:COREEnvelopeRealTimeRequest>");
SoapEnvelope.Append(Environment.NewLine);
SoapEnvelope.Append("</soap:Body>");
SoapEnvelope.Append(Environment.NewLine);
SoapEnvelope.Append("</soap:Envelope>");
cookie.Add(new Uri("https://mn-its.dhs.state.mn.us"), new System.Net.Cookie("OBBasicAuth", "fromDialog"));
cookie.Add(new Uri("https://mn-its.dhs.state.mn.us"), new System.Net.Cookie("ObSSOCookie", "loggedoutcontinue"));
byte[] SoapEnvelopeBytes = null;
SoapEnvelopeBytes = Encoding.UTF8.GetBytes(SoapEnvelope.ToString());
System.Net.WebRequest webRequest = System.Net.WebRequest.Create(PayerDetails.TestURL);
System.Net.HttpWebRequest httpRequest = (System.Net.HttpWebRequest)webRequest;
httpRequest.CookieContainer = cookie;
httpRequest.Method = "POST";
httpRequest.UserAgent = "Mozilla/5.0";
httpRequest.ContentType = "text/xml;charset=UTF-8";
httpRequest.Headers.Add("SOAPAction", "EligXsdRealTimeTransaction");
httpRequest.Credentials = new System.Net.NetworkCredential(PayerDetails.UserID, PayerDetails.Password);
httpRequest.ContentLength = SoapEnvelopeBytes.Length;
requestStream = httpRequest.GetRequestStream();
requestStream.Write(SoapEnvelopeBytes, 0, SoapEnvelopeBytes.Length);
requestStream.Close();
using (HttpWebResponse response = (HttpWebResponse)httpRequest.GetResponse())
{
StreamReader readStream = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
Response271 = readStream.ReadToEnd();
}
答案 0 :(得分:2)
决定是否要发送SOAP 1.1或SOAP 1.2消息。
对于SOAP1.1,请更改:
SoapEnvelope.Append("\"http://www.w3.org/2003/05/soap-envelope\"");
到此:
SoapEnvelope.Append("\"http://schemas.xmlsoap.org/soap/envelope/\"");
对于SOAP1.2,请更改:
httpRequest.ContentType = "text/xml;charset=UTF-8";
httpRequest.Headers.Add("SOAPAction", "EligXsdRealTimeTransaction");
到此:
httpRequest.ContentType = "application/soap+xml; charset=utf-8;action=EligXsdRealTimeTransaction";