gpt4 book ai didi

c# - 无法在地址公开 WCF 端点

转载 作者:太空宇宙 更新时间:2023-11-03 10:42:05 24 4
gpt4 key购买 nike

问题

我无法通过端点指定地址公开 WCF 服务。

例如我的端点地址是:http://localhost:36793/services/main

当我使用 Visual Studio 托管 WCF 服务并尝试访问该地址时,我收到了 http 404 错误(未找到)。

我希望能够通过将 ?wsdl 应用于地址末尾来查看地址的 WSDL。

第二个奇怪的事情是,我可以通过在地址中指定 SVC 来访问该地址。

示例:http://localhost:36793/ServiceManager.svc?wsdl

环境

  • Windows 8.1
  • Visual Studio 2013 更新 1
  • IIS Express 通过 Visual Studio 托管 Web 服务

想法

有些东西告诉我,这要么是 Web 服务的配置问题,要么是 IIS 中没有完全配置的问题。

任何帮助将不胜感激,我花了相当多的时间试图解决这个问题。请参阅下面的我的 Web 配置。

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

<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<client />
<services>
<service behaviorConfiguration="MexTypeBehaviour" name="Server.ServiceManager">
<clear />
<endpoint address="Main" binding="basicHttpBinding" name="Main" contract="Server.IServiceManager" />
<endpoint address="Mex" binding="mexHttpBinding" name="Mex" contract="Server.IServiceManager" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:36793/services" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MexTypeBehaviour" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>

</configuration>

最佳答案

如果 WCF 服务由 IIS 托管,则 *.svc 的位置真正决定服务 URL - 不是 <host>/<baseAddresses> 中的任何设置或 <endpoint> .

您的服务基础 URL 是 http://yourservername:36793/ServiceManager.svc - 并且您不能通过在配置中指定其他内容来更改它。

由于您已经定义了一个 Main您的服务的相对地址,您应该能够在以下位置调用您的服务方法

http://localhost:36793/ServiceManager.svc/Main

The second strange thing is that I am able to get access to the address by specifying the SVC in the address.

这并不奇怪 - 这是内置到 WCF 中的 IIS 托管行为。这是一个特性 - 而不是错误。

如果您希望能够自由定义服务 URL,则需要使用自托管 提供控制台应用程序或 Windows 服务来托管您的 WCF 服务基础结构。

关于c# - 无法在地址公开 WCF 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24984231/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com