不支持WCF“内容类型”;错误
本文关键字:内容类型 错误 类型 WCF 不支持 | 更新日期: 2023-09-27 18:06:18
当我试图连接到我的WCFService时,发生了以下错误。
内容类型text/xml;服务不支持Charset =utf-8http://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) ;
}
我被这个错误卡住了,如果有人知道请帮助。
我怀疑您的WCF服务有WSHttpBinding
或类似的绑定-您需要相应地更改客户端绑定(目前使用BasicHttpBinding
)以使其工作…