【发布时间】:2011-08-17 16:44:07
【问题描述】:
我大致遵循WCF The Right Way ... The Manual Way 中的方法来设置我的 WCF 服务。
我有一个手动生成的代理类,如下所示:
// Setup a client so we can call our web services.
public class EmployeeClient :IEmployeeService
{
private readonly IEmployeeService EmployeeChannel;
public EmployeeClient(Binding binding, string address)
{
var endpointAddress = new EndpointAddress(address);
EmployeeChannel = new ChannelFactory<IEmployeeService>
(binding, endpointAddress).CreateChannel();
}
public EmployeeResponse SaveOrUpdateEmployee(EmployeeContract employee)
{
return EmployeeChannel.SaveOrUpdateEmployee(employee);
}
}
然后我想调用其中一些服务。但我不想使用任何配置文件(我正在设置一些集成测试,并且我不想要比需要更多的依赖项。)
我目前正在尝试这样称呼他们:
serviceHost = SelfServiceHost.StartupService();
employeeClient = new EmployeeClient(new BasicHttpBinding(),
SelfServiceHost.StartUpUrl);
EmployeeResponse employeeResponse = employeeClient.SaveOrUpdateEmployee(emp);
当我这样做时,我得到了这个异常:
System.ServiceModel.ProtocolException:内容类型文本/xml;服务 http://localhost:8090/EmployeeService 不支持 charset=utf-8。客户端和服务绑定可能不匹配。 ---> System.Net.WebException: The remote server returned an error: (415) Cannot processing the message because the content type 'text/xml; charset=utf-8' 不是预期的类型 'application/soap+xml; charset=utf-8'..
我需要怎么做才能调用仅使用代码的服务?
【问题讨论】:
-
为了将来参考和在此评论发布时,问题中发布的教程链接不再加载教程。我无法在其他地方找到该教程,但能够在此处找到本教程的快速参考,其中包含示例项目代码:codeproject.com/Articles/114139/…