为什么我看到"HTTP错误400.请求主机名无效." 连接到wcf服务时

hwa*_*wak 8 c# wcf wsdl

美好的一天,帮助我,请了解情况:

连接到wcf服务只能在本地获得

http://localhost:50233/Service1.svc?wsdl
Run Code Online (Sandbox Code Playgroud)

当从LAN上的另一台机器测试化合物时,我看到错误400

http://computer:50233/Service1.svc?wsdl
Run Code Online (Sandbox Code Playgroud)

我发现这可能是由MaxFieldLength引起的,因此我按照此处的建议编辑了注册表,但它不会改变结果.

C: \ Users \ user> ping computer

Pinging 192.168.0.11 with 32 bytes of data:

Reply from 192.168.0.11: bytes = 32 time <1ms TTL = 127

Reply from 192.168.0.11: bytes = 32 time <1ms TTL = 127

Reply from 192.168.0.11: bytes = 32 time <1ms TTL = 127

Reply from 192.168.0.11: bytes = 32 time <1ms TTL = 127

Ping statistics for 192.168.0.11:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 0ms, Maximum = 0ms, Average = 0ms
Run Code Online (Sandbox Code Playgroud)

停止服务时,远程计算机上的错误更改为

"Web page not available"
Run Code Online (Sandbox Code Playgroud)

防火墙的规则允许端口50233上的所有传入连接.

连接到本地地址时

http://computer:50233/Service1.svc?wsdl
Run Code Online (Sandbox Code Playgroud)

我看到相同的错误400.

删除或替换IP上的"localhost"时

<binding protocol="http" bindingInformation="*:50233:localhost" />
Run Code Online (Sandbox Code Playgroud)

File\My Documents\IISExpress\config\applicationhost.config

连接变得不可用.

当您添加另一个绑定

<Binding Protocol="http" bindingInformation="*:50233:localhost" />

<Binding Protocol="http" bindingInformation="*:50233:192.168.0.11" />
Run Code Online (Sandbox Code Playgroud)

尝试开始发誓时服务程序"[9632] iisexpress.exe"

代码失败-1073741816(0xc0000008)'指定了无效句柄'.

Windows 8,Visual Studio 2013,使用内置的IIS Express,两台计算机都在同一个域中.

hwa*_*wak 13

命令执行(以管理员身份)

netsh http add urlacl url=http://computer:50233/ user=Everyone
Run Code Online (Sandbox Code Playgroud)

帮助改变了503的400错误

现在看我的wsdl,我刚刚添加了一个参考

<Binding Protocol="http" bindingInformation="*:50233:computer" /> 
<Binding Protocol="http" bindingInformation="*:50233:192.168.0.11" /> 
<Binding Protocol="http" bindingInformation="*:50233:localhost" /> 
Run Code Online (Sandbox Code Playgroud)

它开始工作了!

谢谢大家,这是一个很棒的地方

  • 如果您想在Visual Studio中运行的Web项目中执行此操作,则applicationhost.config位于[project root] \.vs\config\applicationhost.config中 (3认同)
  • 你在哪里添加这个引用 &lt;Binding Protocol... ? (2认同)