我创建了一个名为MiniCalc的基本计算器服务,该服务只有两个操作。添加和Mul,并将其托管在控制台应用程序中。无法使用“添加服务参考”生成自托管服务的代理
using(ServiceHost host = new ServiceHost(typeof(MiniCalcService.Service),
new Uri("http://localhost:8091/MiniCalcService")))
{
host.AddServiceEndpoint(typeof(MiniCalcService.IService),
new BasicHttpBinding(),
"Service");
host.Open();
Console.Write("Press ENTER key to terminate the MiniCalcHost . . . ");
}
然后创建了一个控制台应用程序来消费服务和通过创建一个代理类手动创建的代理,然后创建的ChannelFactory来调用服务。
EndpointAddress ep = new EndpointAddress("http://localhost:8091/MiniCalcService/Service");
IService proxy = ChannelFactory<IService>.CreateChannel(new BasicHttpBinding(),ep);
我能够正确调用服务契约并按预期检索结果。
现在我想使用Add Service Reference
创建代理。
我收到以下错误,当我在添加服务引用窗口
There was an error downloading 'http://localhost:8091/MiniCalcService/Service'.
The request failed with HTTP status 400: Bad Request.
Metadata contains a reference that cannot be resolved: 'http://localhost:8091/MiniCalcService/Service'.
Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:8091/MiniCalcService/Service. The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
If the service is defined in the current solution, try building the solution and adding the service reference again.
我缺少什么或者做错了点击Go?
当您访问.SVC在浏览器中它显示了你的服务没有提供有关它的信息如何使用一些例如什么? – 2012-03-24 13:18:52
没有.svc文件。我只创建了一个Service.cs及其对应的IService.cs。请不要介意我的无知,但.svc文件是必要的,我们是否应该使用工具来生成代理并使用该服务? – Animesh 2012-03-24 13:25:35
无知是如果你从未问过。没有人知道一切。在某些时候,你需要从零开始。看到我的答案。 – 2012-03-24 13:50:27