我在访问自托管WCF服务中的第二个端点时遇到错误。以下是我的代码:
Uri HttpUri = new Uri("http://localhost:8092/MyService/HttpService");
ServiceHost host = new ServiceHost(typeof(PollService),HttpUri);
host.AddServiceEndpoint(typeof(ISub), myBinding, ""); //My binding is my custom binding and this end point is working fine.
host.AddServiceEndpoint(typeof(IFocus),
new BasicHttpBinding(),
new uri("http://localhost:8092/MyService/Focusservice"));
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
host.Open();
从代码我可以访问我的自定义绑定网址:
http://localhost:8092/MyService/HttpService`
但我无法访问:
http://localhost:8092/MyService/Focusservice
在WCF测试客户端访问它时,它会抛出错误,如下所示:
错误:无法从
上的MSDN文档http://localhost:8092/MyService/basicbinding
获取元数据 如果这是您有权访问的Windows(R)Communication Foundation服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅link交换错误。 URI:
http://localhost:8092/MyService/basicbinding
元数据包含无法解析的引用:http://localhost:8092/MyService/basicbinding
。内容类型application / soap + xml;服务
http://localhost:8092/MyService/basicbinding
不支持charset = utf-8。客户端和服务绑定可能不匹配。远程服务器返回错误:(415)无法处理消息,因为内容类型为'application / soap + xml; charset = utf-8'不是预期的类型'text / xml;字符集= UTF-8' 。
HTTP GET错误。 URI:
http://localhost:8092/MyService/basicbinding
下载'http://localhost:8092/MyService/basicbinding'
时出错。请求失败,HTTP状态为400:错误请求。