我松散地遵循WCF The Right 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; 字符集=utf-8'..
我需要做什么才能调用仅使用代码的服务?