[英]IIS hosted WCF Service return HTTP 400 Bad Request
我一直在寻找几个小时,但我找不到解决方案。 我将简要解释一下。
我正在学习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 Bad Request
最后,如果我从配置文件中删除地址部分一切正常。 但其他困惑的是,在我的另一台计算机上面的情况(提供地址)后,我可以到达该服务。 所以,我真的厌倦了为什么这个在一台计算机上工作而不在另一台计算机上工作。 有人可以向我解释一下吗?
我知道它有点长,但我必须清楚地解释它。 谢谢
根据我的搜索,我不应该提供一个地址。
msdn.microsoft.com/en-us/library/aa751792(v=vs.110).aspx
您必须始终为IIS托管的服务端点使用相对端点地址。 如果端点地址未指向承载公开端点的服务的IIS应用程序,则提供完全限定的端点地址(例如,localhost / MyService.svc)可能导致服务部署中的错误。 使用托管服务的相对端点地址可以避免这些潜在的冲突。
我认为这将解决您的问题:
将此端点添加到您的服务:
<endpoint address="mex" binding="mexHttpBinding"
bindingConfiguration="" contract="IMetadataExchange" />
并将service
的name
属性更改为服务类的全名:
<service behaviorConfiguration="EmployeeServiceBehaviour"
name="Namespace.EmployeeConfigurationClass">
希望就够了
这可能有所帮助。 我只花了2个多小时试图让这个工作。 我使用FF及其设置作为默认浏览器。
在FF中,它在我的URL末尾添加了一个/
http://services.tester.dev/VehicleFeedService.svc/
它返回了一个NetworkError: 400 Bad Request
但是在IE或Chrome中,它并没有把/放在最后,它工作正常。
有一点需要注意..即使在FF给了我400个不良请求, ?wdsl
确实有效
http://services.tester.dev/VehicleFeedService.svc?wsdl
似乎/正在导致问题
您可以尝试fiddler并尝试svcTracer,它可以为您提供大量的调试信息,您也可以在服务器上使用includeExceptionDetailInFaults=true
标志,但重要的是标记它并不总是正确地将此信息发送给客户端特别是如果客户是外部实体。 有了这个警告,下面是提示如何使用它。
<serviceBehaviors>
<behavior name="ServiceBehavior">
....
<serviceDebug includeExceptionDetailInFaults="true" />
....
</behavior>
</serviceBehaviors>
快乐调试:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.