我大致遵循WCF The Right Way ... The Manual Way中的方法来设置我的WCF服务。使用手动代码(无配置或自动编码)调用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: Content Type text/xml; charset=utf-8 was not supported by service http://localhost:8090/EmployeeService . The client and service bindings may be mismatched. ---> System.Net.WebException: The remote server returned an error: (415) Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'..
什么我需要做的就是我的服务,只有代码的工作打个电话?
以供将来参考和评论的帖子的,教程链接张贴在问题不再加载教程。我一直无法找到其他地方的教程,但能够在这里找到本教程的快速参考和示例项目代码:http://www.codeproject.com/Articles/114139/WCF-The-Right-Way-快速参考指南 – Sean