开发者

There was no endpoint listening at <urlToMex> that could accept the message

开发者 https://www.devze.com 2023-01-19 16:21 出处:网络
I have a WCF-service running inside a windows service. There is an mex-endpoint at http://localhost/...

I have a WCF-service running inside a windows service. There is an mex-endpoint at http://localhost/...

I can navigate to it via a browser b开发者_JAVA百科ut if I use MetadataResolver.Resolve, the above mentioned exception will be thrown (with inner exception of "The remote server returned an error: (404) Not Found.").

The only difference I spotted is, that the browser uses a get and Visual Studio a post.

What can I do to make that run?

Here the server-side:

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();
}

Here the config:

<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>

Here the client-side:

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
    }
}

I hope, it's clearer now!?


When you're configuring your ServiceHost, you're not adding an endpoint for IMetadataExchange, so while you're exposing WSDL, you're not exposing the MEX endpoint. From Nicholas Allen blog:

_serviceHost.AddServiceEndpoint(
   typeof(IMetadataExchange),
   MetadataExchangeBindings.CreateMexHttpBinding(),
   "http://localhost:8081/WindowsServiceWcf/service/mex"
);
0

精彩评论

暂无评论...
验证码 换一张
取 消