C# 从web浏览器调用WCF服务方法
我想从web浏览器运行我的服务:http://localhost:443/TestService//RunTest/data/test 这对我不起作用C# 从web浏览器调用WCF服务方法,c#,wcf,rest,azure,web,C#,Wcf,Rest,Azure,Web,我想从web浏览器运行我的服务:http://localhost:443/TestService//RunTest/data/test 这对我不起作用 This page can’t be displayed •Make sure the web address http://localhost:443 is correct. •Look for the page with your search engine. •Refresh the page in a few minutes. 如何解
This page can’t be displayed
•Make sure the web address http://localhost:443 is correct.
•Look for the page with your search engine.
•Refresh the page in a few minutes.
如何解决这个问题-重新定义端点-如何解决?
WCF服务:
//TestService.svc.cs
public class TestService : ITestService
{
public string RunTest(string data)
{
return string.Format("You entered: {0}", data);
}
}
//ITestService.cs
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/RunTest/data/{data}")]
string RunTest(string data)
{
return string.Format("You entered: {0}", proxyDomain);
}
//Web.config
<system.serviceModel>
<services>
<!-- This section is optional with the default configuration introduced
in .NET Framework 4.5.1 -->
<service
name="TestService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:443/TestService/"/>
</baseAddresses>
</host>
<endpoint address="http://localhost:443/TestService"
binding="wsHttpBinding"
contract="ITestService" />
</service>
</services>
</system.serviceModel>
另外,根据我的经验,当我运行它时,WCF客户端将以端口54388打开,您将无法直接通过浏览器进行测试。 相反,您应该使用WCF测试客户端: 使用浏览器可以做的是查看是否可以访问WSDL。 浏览器中的WSDL调用示例:
http://localhost:8080/DecisionService/ws/PreTradeChecksRuleApp/1.0/PreTradeChecks/1.0?WSDL
您应该向webHttpBinding添加/更改端点绑定属性,如下所示:
<endpoint address="http://localhost:443/TestService"
binding="webHttpBinding"
contract="ITestService" behaviorConfiguration="web" />
或
在这两种情况下,您都必须添加:
注:
1您必须将属性behaviorConfiguration添加到webBinding并添加行为配置
2在第二种解决方案中,您必须更改基址的名称,因为您不能将两个端点配置为相同的基址。如果有人知道如何进行配置,请告诉我,这也会对我有所帮助
致意
<endpoint address="http://localhost:443/TestService"
binding="wsHttpBinding"
contract="ITestService" />
<endpoint address="http://localhost:443/TestService/web"
binding="webHttpBinding"
contract="ITestService" behaviorConfiguration="web"/>
<behaviors>
...
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
...
</behaviors>