Wcf 使用HttpWebRequest返回原始soap正文
我尝试向服务发送信息,并使用此代码返回原始soap主体。可能吗Wcf 使用HttpWebRequest返回原始soap正文,wcf,soap,httpwebrequest,Wcf,Soap,Httpwebrequest,我尝试向服务发送信息,并使用此代码返回原始soap主体。可能吗 DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(GetInfoRequest)); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://localhost/Service.svc/soap/GetDataSoa
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(GetInfoRequest));
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://localhost/Service.svc/soap/GetDataSoap");
GetInfoRequest message = new GetInfoRequest();
message.data = new List<int>();
message.data.Add(268435458);
message.data.Add(99);
MemoryStream stream1 = new MemoryStream();
serializer.WriteObject(stream1, message);
stream1.Position = 0;
StreamReader sr = new StreamReader(stream1);
string t = sr.ReadToEnd();
ASCIIEncoding encoding = new ASCIIEncoding();
request.Timeout = 99999999;
request.ContentLength = t.Length;
//request.ContentType = "application/json";
request.Method = "POST";
request.Headers.Add("SOAPAction: \"http://localhost/Service.svc/soap/GetDataSoap\"");
request.Accept = "text/xml; charset=utf-8";
request.ContentType = "application/json; charset=utf-8";
using (Stream requestStream = request.GetRequestStream())
{
var bytes = Encoding.UTF8.GetBytes(t);
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
//serializer.WriteObject(stream1, message);
//requestStream.Flush();
}
var response = (HttpWebResponse)request.GetResponse();
var abc = new StreamReader(response.GetResponseStream()).ReadToEnd();
TextBox1.Text = abc;
DataContractJsonSerializer序列化程序=新的DataContractJsonSerializer(typeof(GetInfoRequest));
HttpWebRequest请求=(HttpWebRequest)HttpWebRequest.Create(“http://localhost/Service.svc/soap/GetDataSoap");
GetInfoRequest消息=新建GetInfoRequest();
message.data=新列表();
message.data.Add(268435458);
message.data.Add(99);
MemoryStream stream1=新的MemoryStream();
serializer.WriteObject(流1,消息);
1.位置=0;
StreamReader sr=新的StreamReader(stream1);
字符串t=sr.ReadToEnd();
ascienceoding encoding=新的ascienceoding();
请求超时=9999999;
request.ContentLength=t.Length;
//request.ContentType=“application/json”;
request.Method=“POST”;
request.Headers.Add(“SOAPAction:\”http://localhost/Service.svc/soap/GetDataSoap\"");
request.Accept=“text/xml;charset=utf-8”;
request.ContentType=“application/json;charset=utf-8”;
使用(Stream requestStream=request.GetRequestStream())
{
var bytes=Encoding.UTF8.GetBytes(t);
requestStream.Write(字节、0、字节、长度);
requestStream.Close();
//serializer.WriteObject(流1,消息);
//requestStream.Flush();
}
var response=(HttpWebResponse)request.GetResponse();
var abc=newstreamreader(response.GetResponseStream()).ReadToEnd();
TextBox1.Text=abc;
不,这是不可能的。您正在发送JSON请求并期望SOAP响应。那是行不通的。您必须向SOAP服务发送有效的SOAP请求并获得SOAP响应。因此,当我需要发送SOAP请求时,是某个序列化程序将我的自定义类序列化为SOAP请求?序列化与SOAP请求无关。SOAP是一种协议,您必须创建正确的SOAP请求并将序列化类作为其内容传递。SOAP请求必须具有服务所期望的所有特性。