简体   繁体   English

C#RESTful WCF Web服务错误

[英]C# RESTful WCF WebService error

I created a restful/json web service that i can consume with my browser but not adding a service reference from a project: it fails with 我创建了一个restful / json Web服务, 可以通过浏览器使用它,但是不能从项目中添加服务引用:

EndpointNotFoundException: no endpoint listening on /.../GetDevicses, Inner exception: remote server not found (404). EndpointNotFoundException:没有端点在/.../GetDevicses上侦听,内部异常:找不到远程服务器(404)。

One thing i think is important to notice is that in my browser i call uri .../Devices whereas EndpointNotFoundException seems to look for .../GetDevices. 我认为必须注意的一件事是,在浏览器中,我调用uri ... / Devices,而EndpointNotFoundException似乎在查找... / GetDevices。

My service exposes only one method: 我的服务仅公开一种方法:

[OperationContract]
[WebGet( RequestFormat = WebMessageFormat.Json, UriTemplate = "/Devices" )]
DeviceInfoRecord[] GetDevices();

Firewalls are disabled and since i can consume from browser i think service configuration is ok, but i'm not sure about client configuration. 防火墙被禁用,并且因为我可以从浏览器中使用,所以我认为服务配置还可以,但是我不确定客户端配置。

Here is client configuration: 这是客户端配置:

    <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>

Here is server configuration: 这是服务器配置:

<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>

I tried several suggested solutions with no luck so i hope some expert can help. 我没有运气就尝试了几种建议的解决方案,因此希望一些专家可以提供帮助。 Thanks. 谢谢。

I am not sure about your requirement. 我不确定您的要求。 But if you want to have proxy created for your service, then REST service will not provide what you want. 但是,如果要为服务创建代理,则REST服务将无法提供所需的内容。

you must have to add endpoint something like "basicHttpBinding" to created proxy and use it in your code. 您必须必须将诸如“ basicHttpBinding”之类的端点添加到创建的代理中,并在您的代码中使用它。

you can try adding end point and then try adding service serference 您可以尝试添加端点,然后尝试添加服务服务

<endpoint address="" binding="basicHttpBinding" 
              contract="WcfServiceLibrary2.IService">

in this way your service can be exposed to two different endpoints. 这样,您的服务可以暴露给两个不同的端点。 (Rest and Soap). (休息和肥皂)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM