Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I only got the .svc link

what should i do to call wcf method.

C#
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();

what should be write in xmlString

Thanks,
Jie
Posted

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
 
Share this answer
 
Comments
zjkhhbwj 29-Apr-14 21:53pm    
3q very much
Sergey Alexandrovich Kryukov 30-Apr-14 0:31am    
Does it mean "tricky"? Your writing it tricky. :-) (And the use of Service Contract is simple, compared to the attempt to create a soap message on low level.)
Are you going to accept the answer formally?
—SA
zjkhhbwj 30-Apr-14 0:36am    
I write the right soap xml request but i got 500 error from wcf service .
Sergey Alexandrovich Kryukov 30-Apr-14 3:50am    
From your information, it's unclear what could be wrong.
—SA
HTML
<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
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 30-Apr-14 4:06am    
Do not post your comments as solution! Use 'Have a Question or Comment' instead...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900