我大致遵循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