我已经搜索了几个小时,但找不到解决方案。我将简要说明。
我正在学习 WCF 服务。我刚刚创建了一个服务并浏览了它。这是配置文件:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="EmployeeServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="EmployeeServiceBehaviour" name="EmployeeConfiguration">
<endpoint address="http://localhost:2005/EmployeeService.svc" binding="basicHttpBinding"
bindingConfiguration="" contract="IEmployeeConfiguration" />
</service>
</services>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
</system.web>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
从 Visual Studio 浏览时似乎没有问题。效果很好。
其次,我试图在 IIS 上发布它。我正在做的是:
我将服务发布到文件夹并将此服务添加到 IIS。
我选择3006端口作为端口。
在它的配置文件下面。请注意,我还将配置中的端口更改为 3006
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="EmployeeServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="EmployeeServiceBehaviour" name="EmployeeConfiguration">
<endpoint address="http://localhost:3006/EmployeeService.svc" binding="basicHttpBinding"
bindingConfiguration="" contract="IEmployeeConfiguration" />
</service>
</services>
</system.serviceModel>
<system.web>
<compilation/>
</system.web>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
我正在等待顺利运行但是:
IIS 从 Chrome 给我一个空白页面
来自资源管理器的 HTTP 400 错误请求
最后,如果我从配置文件中删除地址部分,一切正常。但另一个令人困惑的事情是,在上述情况(提供的地址)之后我的另一台计算机上我可以访问该服务。所以,我真的厌倦了寻找为什么这在一台计算机上工作而不在另一台计算机上工作。谁能给我解释一下?
我知道它有点长,但我必须解释清楚。 谢谢
最佳答案
根据我的搜索,我不应该提供地址。
msdn.microsoft.com/en-us/library/aa751792(v=vs.110).aspx
You must always use relative endpoint addresses for IIS-hosted service endpoints. Supplying a fully-qualified endpoint address (for example, localhost/MyService.svc) can lead to errors in the deployment of the service if the endpoint address does not point to the IIS-application that hosts the service exposing the endpoint. Using relative endpoint addresses for hosted services avoids these potential conflicts.
关于c# - IIS 托管的 WCF 服务返回 HTTP 400 错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24855068/