WCF“不支持内容类型”错误
当我尝试连接到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑您的 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 usingBasicHttpBinding
) accordingly to make it work...