The data returned by the WCF service contains special characters, causing an error when the client attempts to receive it!"

30 views Asked by At

"When the WCF service returns data containing a special character, such as the thumbs-up symbol , the client encounters an error upon receiving it:

An error occurred while receiving the HTTP response for http://xxxx/xx.svc. This may be due to the service endpoint binding not using the HTTP protocol. It could also be caused by the server terminating the HTTP request context (possibly due to the service being closed). Refer to the server logs for more details.

How can this be addressed?"

1

There are 1 answers

0
QI You On

First of all, I think your question should have nothing to do with special characters. It is recommended that you check whether the WCF service and client configurations are consistent. You can also take a look at the service code.

Usually such emojis are transmitted via Unicode-type string.

When the client receives it, if it is a console output, add the following code:

Console.OutputEncoding = Encoding.UTF8;

Here's a simple example of what I did:

Service code:

public interface IService1
{

    [OperationContract]
    string GetEmjio(string str);
}





 public string GetEmjio(string str)
 {
     return string.Format("ServiceTest"+str);
 }

client code:

 ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
 Console.OutputEncoding = Encoding.UTF8;
 Console.WriteLine(client.GetEmjio(""));
 Console.ReadLine();

Output:

enter image description here