dotnet / wcf

This repo contains the client-oriented WCF libraries that enable applications built on .NET Core to communicate with WCF services.
MIT License
1.7k stars 557 forks source link

"The encoding in the declaration 'ISO-8859-1' does not match the encoding of the document 'utf-8' " #2550

Open mehrdadniroomand opened 6 years ago

mehrdadniroomand commented 6 years ago

Hi there When I want to add a web services(asmx,wsdl) to the asp.net core2.0 v15.5, I will encounter this error in the status box: "The encoding in the declaration 'ISO-8859-1' does not match the encoding of the document 'utf-8' " but in webform or mvc projects it works well with out any error. How can I fix this error?

mlacouture commented 6 years ago

Hi @mehrdadniroomand, is it possible to share the service address (if public?) or the service wsdl so we can investigate?

thanks,

mehrdadniroomand commented 6 years ago

Yes of course. http://185.4.28.100/class/sms/webservice3/server.php?wsdl http://37.130.202.188/class/sms/wsdlservice/server.php?wsdl

mlacouture commented 6 years ago

@mehrdadniroomand thank you for the provided information, we will investigate.

charce36 commented 6 years ago

I have the same problem using "Microsoft WCF Web Service Reference Provider" over .NET Core.

With "Add service reference" over .Net classic projects works without problems.

Any suggestion?

brutusmcforce commented 5 years ago

@mehrdadniroomand @charce36 I don't know if you guys got this working, but I worked around the issue with these steps:

  1. Download the wsdl file
  2. Change the encoding attribute to "UTF-8"
  3. Generate the service classes from your local file
  4. Change "Uri" in ConnectedService.json to the real URL (it points to your local file now)

Seems like it only cares about encoding when adding the reference, since consuming the service works fine after doing this.

funky81 commented 5 years ago

@mehrdadniroomand @charce36 I don't know if you guys got this working, but I worked around the issue with these steps:

  1. Download the wsdl file
  2. Change the encoding attribute to "UTF-8"
  3. Generate the service classes from your local file
  4. Change "Uri" in ConnectedService.json to the real URL (it points to your local file now)

Seems like it only cares about encoding when adding the reference, since consuming the service works fine after doing this.

Hi @magnusvw , it seems this method, doesnt work for me. It still response with the same error message

The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (text/xml; charset=utf-8)

Joe-Goodall commented 4 years ago

Is there a fix for this yet? I am still getting the problem which is preventing me from moving over to dot net core.

dasetser commented 4 years ago

@Joe-Goodall We have not made a fix for this yet, it's still in our backlog to get to. Are you not able to work around it using an approach similar to what's been posted? It sounds like this is just a problem of the serialization code reading the wsdl and having the encoding not match what's declared.

For the wsdls provided I can work around it by simply saving the wsdl file (from ?singlewsdl) to disk and running the tool on the local file instead of the url. It's not ideal to have to use a workaround, but from my current understanding this shouldn't be a blocking problem because you should be able to take the text from the wsdl and save it with an encoding that works.

Joe-Goodall commented 4 years ago

@dasetser How to do I go about downloading the wsdl file?

The service I am trying to use is http://api.despatchbay.com/soap/v15/shipping.php?wsdl

dasetser commented 4 years ago

@Joe-Goodall Going to http://api.despatchbay.com/soap/v15/shipping.php?singlewsdl shows you the full text of the wsdl file. You can just copy paste it to a text file or use your browser's save feature (Ctrl+S on most browsers), and save it with the .wsdl extension. Then you can pass in the full path of the wsdl file to the tool.

jardg commented 4 years ago

Hi. I got the webservice working with the approach above. But since the server uses ISO-8859-1 when I am receiveing the answer I get :

The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 869 bytes of the response were: ...

Is there any workaround for the answer?Thanks.

Joe-Goodall commented 4 years ago

@dasetser It appears to be that I have misread the original issue. I can generate the code from wsdl file perfectly fine, but when I call a web service method I get the same error as @jardg

dasetser commented 4 years ago

@mconnew Do you have any suggestions for what to do when getting this error at runtime?

jardg commented 4 years ago

I finally got it working thanks to implementing a CustomBinding using this post http://pathfindertech.net/connecting-to-a-php-web-service-with-wcf-in-c/ .
For .Net Core I needed to import the NuGet package System.ServiceModel.Primitives and then make some little changes in the CustomTextMessageBindingElement class I downloaded from the link. Such as not implementing IWsdlExportExtension and his methods and remove BuildChannelListener and CanBuildChannelListener implementations. I put the final code for this class in : https://plnkr.co/edit/Cwa2If679ft4pvSP0bYx Then I only need to do this for the webservice client:

CustomBinding binding = new CustomBinding(new CustomTextMessageBindingElement("iso-8859-1", "text/xml", MessageVersion.Soap11), new HttpTransportBindingElement()); //Or  HttpsTransportBindingElement

webService.Endpoint.Binding = binding;
jsamayoap commented 4 years ago

Following @jardg advice, I managed to consume a ISO-8859-1 encoded SOAP WS:

  1. Create the proxy class in .Net Core
  2. Send a request

Now I'm stuck at serializing the response, I have as response this XML:

`<?xml version="1.0" encoding="ISO-8859-1"?>

-1 4 Documento AAG169947 No Existe ` This is trhowing a System.ServiceModel.CommunicationException, at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody {"There is an error in XML document (1, 415)."} {"The specified type was not recognized: name=':', namespace='', at ."} Can anyone please give me some advice?
okobets commented 3 months ago

Fellows, 3 years later, this issue still exists. How about re-prioritizing, please?