[英]C# RESTful WCF WebService error
我创建了一个restful / json Web服务, 可以通过浏览器使用它,但是不能从项目中添加服务引用:
EndpointNotFoundException:没有端点在/.../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">
这样,您的服务可以暴露给两个不同的端点。 (休息和肥皂)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.