0

这就是我们传出的肥皂在后面的代码中的样子。它给了我一个错误 HTTP 500。我无法控制服务。只是客户端使用这个网络服务 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 中做肥皂的最佳方法。我的意思是像将它附加到 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();

                }
4

1 回答 1

2

决定是否要发送 SOAP1.1 或 SOAP1.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";
于 2013-10-11T16:12:55.603 回答