我在Windows服务中运行了WCF服务。在http://localhost/ ...
处有一个mex-endpoint我可以通过浏览器导航到它但如果我使用MetadataResolver.Resolve,则会抛出上述异常(内部异常“远程服务器返回错误:(404)Not Found。”)。
我发现的唯一区别是,浏览器使用get和Visual Studio一个帖子。
我该怎样做才能让这次跑步?
服务器端:
protected override void OnStart(string[] args) {
_serviceHost = new ServiceHost(new TestService());
var binding = new WSHttpBinding();
_serviceHost.AddServiceEndpoint(typeof(ITestService),
binding,
"http://localhost:8081/WindowsServiceWcf/service");
_serviceHost.Open();
}
这里是配置:
<system.serviceModel>
<services>
<service name="WindowsServiceWcf.TestService" behaviorConfiguration="MexGet" />
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MexGet">
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost/WindowsServiceWcf/service/TestServiceMexAddress" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
这是客户端:
private void SetUpService() {
var mexUri = new Uri("http://localhost/WindowsServiceWcf/service/TestServiceMexAddress");
var metaAddress = new EndpointAddress(mexUri);
try {
var endpoints = MetadataResolver.Resolve(typeof(TestService), metaAddress);
} catch (Exception) {
// above mentioned exception
}
}
我希望,现在更清楚了!?
答案 0 :(得分:0)
当您配置ServiceHost时,您没有为IMetadataExchange添加端点,因此在您公开WSDL时,您不会公开MEX端点。来自Nicholas Allen blog:
_serviceHost.AddServiceEndpoint(
typeof(IMetadataExchange),
MetadataExchangeBindings.CreateMexHttpBinding(),
"http://localhost:8081/WindowsServiceWcf/service/mex"
);