vs 2022 WCF服务应用程序项目模板不使用NET TCP

发布于 2025-02-10 21:06:03 字数 2271 浏览 2 评论 0 原文

我正在尝试将最简单的WCF服务应用程序与net.tcp一起使用,但行之有效。使用VS2022,如果我创建一个新项目并选择WCF服务应用模板,则新项目将使用Web.config文件,service1.svc文件和iservice.svc打开。

Web.config看起来像这样,

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2"/>
  </system.web>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

如果我运行此示例项目,它将加载WCF测试客户端,并显示使用BasichttpBinding运行的服务。完美的。

如果我从&lt;添加binding =“ basichttpsbinding” scheme =“ https” /&gt; < /code> &lt; add binding =“ wshttpBinding” scheme =“ htttp”,则将绑定在配置文件中的绑定。 /&gt; 并运行该项目,WCF测试客户端显示WSHTTPBINDING。伟大的!现在,如果我从&lt; add binding =“ wshttpbinding”中将绑定在配置文件中更改绑定。 .tcp“ /&gt; < /code>并运行项目,WCF测试客户端显示了使用basichttpbinding运行的服务。配置文件中甚至没有basichttpbinding绑定!!!!到底从哪里得到的?我已经尝试了几天来nettcpbinding上班,无论我做什么,都无济于事。我认为我会尝试最简单的事情,这是从一个新鲜的空白项目开始,并做出最简单的更改,但仍然没有运气。我想念什么。我几乎找不到有关获得这项工作的信息。

I'm trying to get the simplest WCF Service Application to work with net.tcp and it's not working. Using VS2022, if I create a new project and select the WCF Service Application Template, the new project opens with a Web.config file, Service1.svc file and a IService.svc.

The Web.config looks like this,

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2"/>
  </system.web>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

If I run this sample project it loads the WCF Test client and shows the service running with the BasicHttpBinding. Perfect.

If I change the binding in the config file from <add binding="basicHttpsBinding" scheme="https" /> to <add binding="wsHttpBinding" scheme="http" /> and run the project, the WCF Test Client shows the WSHttpBinding. Great! Now if I change the binding in the config file from <add binding="wsHttpBinding" scheme="http" /> to <add binding="netTcpBinding" scheme="net.tcp" /> and run the project, the WCF Test Client shows the service running with the BasicHttpBinding. THERE'S NOT EVEN A BasicHttpBinding BINDING IN THE CONFIG FILE!!!!! WHERE THE HELL IS IT GETTING THAT FROM? I've been trying for days to netTcpBinding to work and no matter I do, nothing works. I figured I'd try the simplest thing I could do, which was start with a fresh blank project and make the simplest change, and still no luck. What am I missing. I can find nearly no information on getting this work.

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

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

发布评论

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

评论(1

万人眼中万个我 2025-02-17 21:06:03

首先,您必须了解&lt; 协议图&gt;。该配置在Machine.config文件中显示默认协议映射。

您需要按机器级别覆盖此默认映射
修改Machine.config文件。或者,如果您只想
覆盖IT应用程序范围内,您可以在此部分中覆盖此部分
应用程序配置文件,然后更改映射
单个协议方案。

更一般地,HTTP系统提供的绑定(例如WSHTPBINDING和BASICHTPBINDING)配置为打开事物
默认情况下,默认情况下,默认情况下,nettcpbinding绑定了绑定,以便您必须选择加入以获得支持,例如,对于WS-*规格之一。

您需要修改配置文件,您可以看到如何配置&lt; nettcpbinding&gt; 。如果您在IIS上托管服务,则需要IIS才能启用net.tcp。



如果您需要简单的项目,我建议您从WCF的初学者教程开始。
https://learlen.microsoft.com/en-en--en----- US/dotnet/framework/wcf/获得启动的教程

First you have to understand the meaning of <protocolMapping>. The configuration in shows the default protocol mapping in the machine.config file.

You need to override this default mapping at the machine level by
modifying the machine.config file. Alternatively, if you just want to
override it application-wide, you can override this section in the
application configuration file and change the mapping for the
individual protocol schemes.

More generally, the HTTP system-provided bindings such as wsHttpBinding and basicHttpBinding are configured to turn things on by
default, whereas the netTcpBinding binding turns things off by default so that you have to opt-in to get support, for example, for one of the WS-* specifications.

You need to modify the configuration file, you can see how <netTcpBinding> is configured. If you host your service on IIS, you need IIS to have net.tcp enabled.
netTcpBinding In WCF Service With IIS Hosting

nettcpbinding

default-nettcpbinding

If you need simple projects to start with, I suggest you start with wcf's beginners tutorial.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/getting-started-tutorial

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