简体   繁体   中英

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

EndpointNotFoundException: no endpoint listening on /.../GetDevicses, Inner exception: remote server not found (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.

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.

you must have to add endpoint something like "basicHttpBinding" to created proxy and use it in your code.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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