【发布时间】:2015-03-20 00:49:02
【问题描述】:
这是我第一次使用 WCF Web 服务和 IIS。我托管 WCF Web 服务的方式是通过 .svc 文件。我在 IIS 中添加了一个网站,并将其指向包含 .svc 文件的文件夹。
现在,在配置 IIS 时,它确实要求我输入我输入 localhost 假设的主机名,这将是我网站的地址。
然而,事实并非如此。我正在浏览本地主机并得到 404。现在,当我运行具有 WCF 服务网站项目(包含 .svc 文件的项目)的服务时,它确实填充了 WCF 客户端窗口,该窗口显示以下地址作为我的服务地址:
http://localhost:31893/Employee.svc。我添加我的 web.config 文件仅供参考。
<?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>
<bindings>
<wsHttpBinding>
<binding name="EmployeeServiceBinding" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="16384" maxNameTableCharCount="16384"/>
<security mode="None">
<transport clientCredentialType="None"/>
<message clientCredentialType="None" negotiateServiceCredential="false" establishSecurityContext="false"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="PL.HR.Employees.WebService.HREmployeeWebService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="EmployeeServiceBinding" name="StandardEndpoint" contract="PL.HR.Employees.WebService.IHREmployeeWebService"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="false"/>
</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>
现在,我认为这必须是 VS 在运行时生成的 Visual Studion 开发环境地址。但不,这是我添加到 IIS 中的 WebHost 的地址。这在我的脑海中提出了几个问题:
- Visual Studio 如何知道我的 IIS 映射?
- VS/IIS 生成的这个31893是什么?我不记得在配置 IIS 网站时指定过这样的内容?
- 我指定 Host name= localhost 是否会更改 Visual Studio 生成的 URL 的最终输出中的任何内容?
- 我是否可以控制我的服务的最终 URL 的外观?如果我希望它是 www.xyz.com 怎么办?
【问题讨论】:
-
你能发布一个代码示例吗?此外,您是否 100% 确定您添加的端口实际上与 31893 相关联。这是通过绑定完成的,您必须明确添加额外的端口
-
对于第 4 个问题:localhost 只不过是 IP 地址 127.0.0.1。因此,您可以根据需要命名 URL,例如:www.xyz.com,方法是在
C:\windows\System32\drivers\etc下的主机文件中提及它。只需在您的主机文件中添加这一行127.0.0.1 www.xyz.com -
在我看来,Visual Studio 正在使用 IIS Express。如果您查看 web 下的项目属性,您可以告诉它使用本地 IIS(我相信 IIS Express 是默认设置)。它将是本地主机,并且端口号是动态的。
-
我同意 Tim 和 IIS Express 的最佳猜测。
-
好吧,我已将此 .svc 映射到 IIS,因此无需运行 Visual Studio,我就可以到达此位置。