我怎么能通过HttpWebRequest调用wcf发送soaprequest [英] How could I call wcf by HttpWebRequest send soaprequest

查看:111
本文介绍了我怎么能通过HttpWebRequest调用wcf发送soaprequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只有.svc链接



我该怎么办才能调用wcf方法。



I only got the .svc link

what should i do to call wcf method.

HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create("https://test.svc");
String xmlString =""
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] bytesTowrite = encoding.GetBytes(xmlString);

myWebRequest.Method = "POST";
myWebRequest.ContentLength = bytesTowrite.Length;
myWebRequest.ContentType = "application/soap+xml; charset=utf-8";

Stream newStream = myWebRequest.GetRequestStream();
newStream.Write(bytesTowrite, 0, bytesTowrite.Length);
newStream.Close();

HttpWebResponse response = (HttpWebResponse)myWebRequest.GetResponse();
Stream datastream = response.GetResponseStream();
StreamReader reader = new StreamReader(datastream);

string responseFromServer = reader.ReadToEnd();



应该用xmlString写什么



谢谢,

Jie


what should be write in xmlString

Thanks,
Jie

推荐答案

您需要使用SOAP序列化。请参阅:

http:// msdn .microsoft.com / zh-CN / library / 90c86ass%28v = vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.runtime .serialization.formatters.soap.soapformatter%28v = vs.110%29.aspx [ ^ ]。



但是,我不明白为什么你需要在如此低的水平上工作。如何使用服务合同,你甚至不使用数据,但立即使用接口及其方法?请参阅:

http:// msdn .microsoft.com / zh-CN / library / bb412196%28v = vs.110%29.aspx [ ^ ]。



在这种情况下,更多如果您需要,可以使用SOAP进行非常困难的工作。



-SA
You would need to use SOAP serialization. Please see:
http://msdn.microsoft.com/en-us/library/90c86ass%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.soap.soapformatter%28v=vs.110%29.aspx[^].

However, I don't understand why would you need to work at so low level. How about using Service Contract where you would work not even with the data, but immediately with the interface and its methods? Please see:
http://msdn.microsoft.com/en-us/library/bb412196%28v=vs.110%29.aspx[^].

In this case, more difficult work with SOAP you could leave to non-.NET client, if you even needed it.

—SA


<s:envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:body><s:fault><s:code><s:value>s:Sender</s:value><s:subcode><s:value xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">a:FailedAuthentication</s:value></s:subcode></s:code><s:reason><s:text xml:lang="en-US">At least one security token in the message could not be validated.</s:text></s:reason></s:fault></s:body></s:envelope>





得到此错误



get this error


这篇关于我怎么能通过HttpWebRequest调用wcf发送soaprequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆