内容类型text/xml; 服务不支持charset = utf-8

use*_*483 72 wcf endpoint

我有一个WCF服务的问题.我有一个控制台应用程序,我需要在不使用app.config的情况下使用该服务,因此我必须通过代码设置端点等.我有svc的服务引用,但我不能使用app.config.这是我的代码:

BasicHttpBinding binding = new BasicHttpBinding();

EndpointAddress address = new EndpointAddress("http://localhost:8731/WcfServicio/MiServicio");

MiServicioClient svc = new MiServicioClient(binding, address);
object ob = svc.PaisesObtener();
Run Code Online (Sandbox Code Playgroud)

在我的最后一行,svc.PaisesObtener()我得到错误:

Content Type text/xml; charset=utf-8 was not supported by service
http://localhost:8731/WcfServicio/MiServicio.  The client and service bindings may be mismatched.
Run Code Online (Sandbox Code Playgroud)

Cod*_*ter 142

首先谷歌点击说:

这通常是客户端/服务器绑定中的不匹配,其中服务中的消息版本使用SOAP 1.2(期望application/soap + xml),而客户端中的版本使用SOAP 1.1(发送text/xml).WSHttpBinding使用SOAP 1.2,BasicHttpBinding使用SOAP 1.1.

它通常似乎是一侧的wsHttpBinding和另一侧的basicHttpBinding.

  • 这篇文章现在是谷歌的第一个热门:-D (16认同)
  • @ PedroC88从那我不知道是什么问题.请尝试打开您自己的问题,但请务必显示您尝试过的所有相关配置和步骤,例如,您是否可以从浏览器访问服务的URL以及WcfTestClient.exe是否可以访问该服务. (2认同)

myk*_*kov 25

不要忘记检查绑定相关的代码.所以,如果你写道:

BasicHttpBinding binding = new BasicHttpBinding();
Run Code Online (Sandbox Code Playgroud)

确保所有app.config文件都包含

<endpoint address="..."
          binding="basicHttpBinding" ...
Run Code Online (Sandbox Code Playgroud)

不是

<endpoint address="..."
          binding="wsHttpBinding" ...
Run Code Online (Sandbox Code Playgroud)

或者.


ren*_*ene 8

我今天看到这种行为的时候了

   <service name="A.B.C.D" behaviorConfiguration="returnFaults">
        <endpoint contract="A.B.C.ID" binding="basicHttpBinding" address=""/>
    </service>
Run Code Online (Sandbox Code Playgroud)

在web.config中丢失了.该service.svc文件在那里并得到了服务.花了一段时间才意识到问题不在它自己的绑定配置中......