WCF“不支持内容类型”错误

发布于 2024-11-30 21:04:16 字数 994 浏览 1 评论 0原文

当我尝试连接到 WCFService 时,发生以下错误。

内容类型text/xml;服务不支持 charset=utf-8 http://localhost:1978/Service1.svc。客户端和服务绑定 可能不匹配。

我的服务代码是:

namespace WcfService1
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(string fName, string lName);
    }
}

在客户端表单中,我按如下方式调用此服务:

endPointAddr = "http://localhost:1978/Service1.svc";

BasicHttpBinding httpBinding = new BasicHttpBinding();
httpBinding.TransferMode = TransferMode.Buffered;

EndpointAddress endpointAddress = new EndpointAddress(endPointAddr);

Append("Attempt to connect to: " + endPointAddr);

IService1 proxy = ChannelFactory<IService1>.CreateChannel(httpBinding, endpointAddress);

using (proxy as IDisposable)
{
    string strNew=proxy.GetData(textBox2.Text, textBox1.Text) ;
}

我陷入了该错误,如果有人知道请帮助。

When I am trying to connect to my WCFService the following error occurred.

Content Type text/xml; charset=utf-8 was not supported by service
http://localhost:1978/Service1.svc. The client and service bindings
may be mismatched.

My service code is :

namespace WcfService1
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(string fName, string lName);
    }
}

And in the client form I am calling this service as follows:

endPointAddr = "http://localhost:1978/Service1.svc";

BasicHttpBinding httpBinding = new BasicHttpBinding();
httpBinding.TransferMode = TransferMode.Buffered;

EndpointAddress endpointAddress = new EndpointAddress(endPointAddr);

Append("Attempt to connect to: " + endPointAddr);

IService1 proxy = ChannelFactory<IService1>.CreateChannel(httpBinding, endpointAddress);

using (proxy as IDisposable)
{
    string strNew=proxy.GetData(textBox2.Text, textBox1.Text) ;
}

I am stuck on that error, if anybody knows please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雄赳赳气昂昂 2024-12-07 21:04:16

我怀疑您的 WCF 服务具有 WSHttpBinding 或类似的绑定 - 您需要相应地更改客户端绑定(当前正在使用 BasicHttpBinding)才能使其正常工作...

I suspect that your WCF service has a binding of WSHttpBinding or similar - you need to change the client binding (which is currently using BasicHttpBinding) accordingly to make it work...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文