簡體   English   中英

C#RESTful WCF Web服務錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM