>我创建了一个 restful/json Web 服务,我可以在浏览器中使用它,但没有从项目添加服务引用:它失败了
EndpointNotFoundException: no endpoint listenon/.../GetDevicses,内部异常:找不到远程服务器 (404)。
我认为需要注意的一件事是,在我的浏览器中,我调用uri .../Devices,而EndpointNotFoundException似乎在寻找.../GetDevices。
我的服务仅公开一种方法:
[OperationContract]
[WebGet( RequestFormat = WebMessageFormat.Json, UriTemplate = "/Devices" )]
DeviceInfoRecord[] GetDevices();
防火墙被禁用,因为我可以从浏览器使用,我认为服务配置没问题,但我不确定客户端配置。
以下是客户端配置:
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp defaultOutgoingResponseFormat="Json"/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary2/Service1/"
name="Service1" binding="webHttpBinding"
contract="ServiceReference1.IService" behaviorConfiguration="web" />
</client>
</system.serviceModel>
以下是服务器配置:
<system.serviceModel>
<services>
<service name="WcfServiceLibrary2.Service1">
<endpoint address="" binding="webHttpBinding"
contract="WcfServiceLibrary2.IService"
behaviorConfiguration="restfulBehavior">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary2/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehavior">
<webHttp defaultOutgoingResponseFormat="Json" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我尝试了几个建议的解决方案,但没有运气,所以我希望一些专家可以提供帮助。谢谢。
我不确定你的要求。但是,如果要为服务创建代理,则 REST 服务不会提供所需的内容。
您必须将诸如"basicHttpBinding"之类的端点添加到创建的代理中,并在代码中使用它。
您可以尝试添加端点,然后尝试添加服务服务
<endpoint address="" binding="basicHttpBinding"
contract="WcfServiceLibrary2.IService">
这样,服务可以公开到两个不同的终结点。(休息和肥皂)。