IIS托管WCF服务返回HTTP 400错误的请求 [英] IIS hosted WCF Service return HTTP 400 Bad Request

查看:653
本文介绍了IIS托管WCF服务返回HTTP 400错误的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找了几个小时,但我无法找到解决方案。我将简要解释。

I have been searching for hours, but I could not find the solution. I will explain briefly.

我学习WCF服务。我刚刚创建了一个服务,并浏览它。下面是配置文件:

I am learning WCF Services. I have just created a service and browse it. Here is the config file:

<?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似乎没有问题。它完美的作品。

When browse it from Visual Studio there seems no problem. It works perfectly.

第二,我想它发布在IIS上。我做的是这样的:

Second, I am trying to publish it on IIS. What I am doing is this:

我服务发布到一个文件夹,这个服务添加到IIS。

I publish the service to a folder and add this service to IIS.

我选择端口3006作为端口。

I select port 3006 as a port.

下面的配置文件。请注意,我也改变了口内配置为3006

Below its config file. Note that I also changed port inside config to 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>

和我等着流畅运行,但是:

And I am waiting to run smoothly but:

IIS给我Chrome的空白页

IIS gives me a blank page from Chrome

和HTTP 400从资源管理器坏请求

And HTTP 400 Bad Request from Explorer

最后,如果我从配置中删除地址部分文件一切正常。但其他困惑的是,上述方案后,我的另一台计算机上(地址提供)我能达到的服务。所以,我真的累了搜索,为什么这是工作在一台计算机上,而不是工作的另外一个。可能有人解释给我吗?

Lastly, if I remove address part from config file everything works well. But other confused thing is that, on my other computer after above scenario(address provided) I can reach the service. So, I really tired of searching why this is working on one computer and not working on another one. Could someone explain it to me?

我知道这是一个有点长,但我必须解释清楚。
谢谢

I know it is a bit longer, but I have to explain it clearly. Thanks

推荐答案

根据我的搜索,我不应该提供的地址。

According my searches I should not provide an address.

msdn.microsoft.com/en-us /library/aa751792(v=vs.110).aspx

说:你必须始终使用相对端点地址为IIS托管服务端点。提供一个完全合格的端点地址(例如localhost / MyService.svc)可能会导致在服务的部署错误如果端点地址不指向IIS应用程序托管服务公开的端点。使用相对端点地址为托管服务避免了这些潜在的冲突。

says: 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.

这篇关于IIS托管WCF服务返回HTTP 400错误的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆