添加自定义 ServiceHostFactory 时未找到端点

发布于 2024-12-21 21:27:04 字数 465 浏览 2 评论 0原文

我创建了一个 wcf 应用程序。我没有改变任何东西。使用Service1.GetData(int)。效果很好。我可以在浏览器中输入 wsdl 等等。然后我创建了一个自定义服务主机工厂,它只返回一个新的服务主机,并且该服务永远不会出现。我无法再在浏览器中访问 wsdl。我尝试添加一个自定义 ServiceHost,这样我就可以进行一些调试,但似乎没有找到端点(即使显式调用 AddDefaultEndpoints() 时也是如此。即使我显式地将端点添加到 web.config 时也是如此。

有人会这样做吗?有任何想法可能是什么问题吗?

如果有人愿意看一下,我将代码放在 github 上: https://github.com/devlife/Sandbox/tree/master/WcfService1

I created a wcf application. I didn't change anything. Used the Service1.GetData(int). It works fine. I can hit the wsdl in a browser and everything. Then I created a custom service host factory that simply returns a new service host and the service never comes up. I can no longer get to the wsdl in a browser. I tried adding a Custom ServiceHost so I could do a little debugging and it appears that there are no endpoints being found (even when explicitly calling AddDefaultEndpoints(). This is true even when I explicitly add the endpoint to the web.config.

Does anyone have any ideas as to what the issue could be?

If anyone cares to take a look I put the code on github: https://github.com/devlife/Sandbox/tree/master/WcfService1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜味超标? 2024-12-28 21:27:04

为什么使用ServiceHostFactory?
您要使用 AppFabric/IIS 吗?或自托管服务?

我认为您需要添加一个 MEX 端点。

    <endpoint address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />

Why are you using ServiceHostFactory?
are you going to use AppFabric/IIS? or self hosted services?

I think you need to add a MEX endpoint.

    <endpoint address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />
雨落□心尘 2024-12-28 21:27:04

以下是我在我正在处理的项目中定义 CustomHost 的方式,

<%@ ServiceHost Language="C#" Debug="true" Service="Servicename.Servicename" CodeBehind="Service1.svc.cs" Factory="WcfService1.CustomServiceHostFactory"%>

public class CustomServiceHostFactory : ServiceHostFactory
{
    public CustomServiceHostFactory()
    {

    }

    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        return new CustomServiceHost(serviceType, baseAddresses);
    }
}

public class CustomServiceHost : ServiceHost
{
    public CustomServiceHost()
    {
    }

    public CustomServiceHost(Type serviceType, params Uri[] baseAddresses)
        : base(serviceType, baseAddresses)
    {
    }

    protected override void OnOpening()
    {
        base.OnOpening();
    }

    protected override void OnClosing()
    {
        base.OnClosing();
    }

    protected override void ApplyConfiguration()
    {
        base.ApplyConfiguration();
    }
}

注意,CustomServiceHost 看起来很简单,但这是因为我的解决方案在此 CustomServiceHost 中有大量日志记录和配置,我删除了这些记录和配置,这是不合适的。

我还可以看到的另一个区别是我的 CustomServiceHost 没有添加端点。端点在配置文件中定义如下:

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="Servicename.Servicename" behaviorConfiguration="ServiceBehavior">
    <endpoint address="http://*******.svc" binding="wsHttpBinding" contract="Namespace.IContract" bindingConfiguration="BindingConfig">
    </endpoint>
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="BindingConfig" maxReceivedMessageSize="9291456">
      <security mode="None">
      </security>
      <readerQuotas maxArrayLength="6291456" />
    </binding>
  </wsHttpBinding>
</bindings>

Here is how I have defined a CustomHost in a project I am working on,

<%@ ServiceHost Language="C#" Debug="true" Service="Servicename.Servicename" CodeBehind="Service1.svc.cs" Factory="WcfService1.CustomServiceHostFactory"%>

And this,

public class CustomServiceHostFactory : ServiceHostFactory
{
    public CustomServiceHostFactory()
    {

    }

    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        return new CustomServiceHost(serviceType, baseAddresses);
    }
}

public class CustomServiceHost : ServiceHost
{
    public CustomServiceHost()
    {
    }

    public CustomServiceHost(Type serviceType, params Uri[] baseAddresses)
        : base(serviceType, baseAddresses)
    {
    }

    protected override void OnOpening()
    {
        base.OnOpening();
    }

    protected override void OnClosing()
    {
        base.OnClosing();
    }

    protected override void ApplyConfiguration()
    {
        base.ApplyConfiguration();
    }
}

Note that the CustomServiceHost looks bare, but that is because my solution has a lot of logging and configuration in this CustomServiceHost that I removed and is not appropriate.

The other difference I can see also is that my CustomServiceHost does not add the endpoint. The endpoint is defined in the config file like this,

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="Servicename.Servicename" behaviorConfiguration="ServiceBehavior">
    <endpoint address="http://*******.svc" binding="wsHttpBinding" contract="Namespace.IContract" bindingConfiguration="BindingConfig">
    </endpoint>
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="BindingConfig" maxReceivedMessageSize="9291456">
      <security mode="None">
      </security>
      <readerQuotas maxArrayLength="6291456" />
    </binding>
  </wsHttpBinding>
</bindings>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文