my WCF Rest makes a request to another Rest Api, but it returns the following error:
System.Net.WebException: Connection is terminated: Unexpected sending error. ---> System.IO.IOException: Authentication failed because the remote party closed the transport stream. \ R \ n in System.Net.Security.SslState.StartReadFrame (Byte [] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) \ r \ n in System.Net.Security.SslState.StartReceiveBlob (Byte [] buffer, AsyncProtocolRequest asyncRequest) \ r \ n in System.Net.Security.SslState.CheckCompletionBeforeNextReceive (ProtocolToken message, AsyncProtocolRequest asyncRequest) \ r \ n in System. Net.Security.SslState.StartSendBlob (Byte [] incoming, Int32 count, AsyncProtocolRequest asyncRequest) \ r \ n in System.Net.Security.SslState.ForceAuthentication (Boolean receiveFirst, Byte [] buffer, AsyncProtocolRequest asyncRequest) \ r \ n System.Net.Security.SslState.ProcessAuthentication (LazyAsyncResult lazyResult) \ r \ n in System.Net.TlsStream.CallProcessAuthentication (Object state) \ r \ n in System.Threading.ExecutionContext.RunInternal (ExecutionContext executionContext, ContextCallback callback, Object state , B oolean preserveSyncCtx) \ r \ n in System.Threading.ExecutionContext.Run (ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) \ r \ n in System.Threading.ExecutionContext.Run (ExecutionContext executionContext, ContextCallback callback, Object state) \ r \ n in System.Net.TlsStream.ProcessAuthentication (LazyAsyncResult result) \ r \ n in System.Net.TlsStream.Write (Byte [] buffer, Int32 offset, Int32 size) \ r \ n in System.Net.PooledStream .Write (Byte [] buffer, Int32 offset, Int32 size) \ r \ n in System.Net.ConnectStream.WriteHeaders (Boolean async) \ r \ n --- End of stack trace of internal exception --- \ r \ n in System.Net.WebClient.UploadDataInternal (Uri address, String method, Byte [] data, WebRequest & request) \ r \ n in System.Net.WebClient.UploadString (Uri address, String method, String data) \ r \ n in BS.Control.Save.Send (String body, String to)
where I have the functions is in a library c # called BS, in the, class "Send", and in this I do this:
the
json= {"user":"test","pass":"12345","message":"test 1","number":"12345678"}
using (var WC = new WebClient())
{
JObject response = new JObject();
ResponseD Result = new ResponseD();
try
{
WC.Headers.Add(HttpRequestHeader.Authorization,"Bearer MyCode");
WC.Headers.Add(HttpRequestHeader.ContentType,"application/json");
string baseurl = "url-where receive the post";
response = JObject.Parse(WC.UploadString(new Uri(baseurl), "POST", json));
}
catch(Exception ex)
{
Result.id = "Error";
Result.result = ex.ToString();
}
}
This Exception is present in my local PC, in my IIS server and even in an Azure APPservice .... in my IIS server I configured an SSL to where I have the WCF, but with SSL my WCF continues with the same problem and does not send response...
i was make a console application where i use the same library as my WCF Rest and in this there are no problems, the "response = JObject.Parse (WC.UploadString (new Uri (baseurl)," POST ", json));" Receive answer without problems .... recive a beautiful Json with the information of the id assigned to the request, time issued among other things, but this the only thing I need is the ID and from a ConsoleApp Everything works well ....
The Json of response is:
{
"id": "Error",
"result":
the exception mentioned above and the location in Line where the problem is located and this is where the WC.uploadstring is
}
Can someone help me with this problem?
}
for yourusing() {
have you used the debugger to step thru the code..? – MethodMan