問題背景
最近使用C#編寫了一個WebService,希望通過Java進行調用。使用Visual Studio 2013調試WebService時,可以在瀏覽器中通過localhost地址訪問WSDL文件。
訪問方式如:http://localhost:2256/DataProvider.asmx?WSDL。
但是,當使用http://127.0.0.1:2256/DataProvider.asmx?WSDL或者使用http://[本機IP]:2256/DataProvider.asmx?WSDL時,顯示Bad Request錯誤。
現在希望其他機器訪問本機的WSDL文件,所以要求WebService可以使用IP地址訪問。
開發環境:
1)Windows 7
2)Visual Studio 2013
配置方法
1)找到<我的文檔>/IIS Express文件夾,打開applicationhost.config。
2)在配置文件中找到<sites></sites>標簽。
3)<sites>標簽內包含許多<site>標簽,找到WebService所在的<site>標簽,如 <site name="DataProvider" id="2">。
4)在<site>標簽內找到<bindings>標簽,在<bindings>找到<binding>標簽的bindingInformation屬性,如bindingInformation="*:2256:localhost"。
5)修改localhost為*。有關bindingInformation的詳細信息參考這里。
6)使用管理員權限重新啟動Visual Studio 2013。
7)調試程序。
8)結束。
備注
bindingInformation設置方法:
1)如果希望對所有IP綁定80端口,並且不指定host名稱,則設置為“*:80:”。
2)如果希望對所有IP綁定80端口,並且指定host名稱為microsoft.com,則設置為“*:80:microsoft.com”。
2)如果希望對固定IP(192.168.1.150)綁定8080端口,則設置為“192.168.1.150:8080:”。
與本文類似的文章還有:
