我創建了一個名爲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