2011-01-19 37 views
0

可能重複:
Bad Request 400 while accessing WCF Rest service (WebGet)WebGet方法給出了WCF REST服務應用程序錯誤400 「錯誤的請求」

大家好,

讓我解釋什麼,我有做WCF休息服務。這裏是我的代碼和配置:

  1. IDNNService接口

    [ServiceContract] 
    public interface IDNNService 
    { 
        [WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate = "hello/{Name}")] 
        [OperationContract] 
        string SayHello(string Name); 
    } 
    
  2. 服務類實現接口

    public class DNNService : IDNNService 
    { 
        public string SayHello(string Name) 
        { 
         return string.Format("Hello {0}", Name); 
        } 
    } 
    
  3. 配置文件

    <system.serviceModel> 
        <services> 
         <service behaviorConfiguration="DNNServiceBehavior" name="DNNService"> 
         <endpoint 
           address="" 
           binding="wsHttpBinding" 
           contract="IDNNService"> 
          <identity> 
           <dns value="localhost" /> 
          </identity> 
         </endpoint> 
         <endpoint 
           address="mex" 
           binding="mexHttpBinding" 
           contract="IMetadataExchange" /> 
         <endpoint 
           address="rest" 
           binding="webHttpBinding" 
           behaviorConfiguration="httpBehavior" 
           contract="IDNNService"/> 
         </service> 
        </services> 
        <behaviors> 
         <serviceBehaviors> 
         <behavior name="DNNServiceBehavior"> 
          <serviceMetadata httpGetEnabled="true" /> 
          <serviceDebug includeExceptionDetailInFaults="false" /> 
         </behavior> 
         </serviceBehaviors> 
         <endpointBehaviors> 
          <behavior name="httpBehavior"> 
          <webHttp/> 
          </behavior> 
         </endpointBehaviors> 
        </behaviors> 
    </system.serviceModel> 
    

我能夠生成我的SVC文件與WSDL

返回正確的信息,但問題是,當我嘗試訪問我的實際方法

http://localhost/DC560X_rest/DesktopModules/DNNCentric-RestService/Entities/DNNService.svc/rest/hello/prabhakar 
  1. IE Dispaly 「400錯誤請求」
  2. Firefox顯示空白頁面

請幫我一把。 在此先感謝

+0

你爲什麼在你的模板裏有兩個'}'? – 2011-01-18 15:24:34

回答

2

你的URL看起來堅果如松鼠等

設置服務的URL

<system.serviceModel> 
    <services> 
     <service behaviorConfiguration="DNNServiceBehavior" name="DNNService"> 
     <endpoint 
       address="http://*:12345/Derp" 
       binding="wsHttpBinding" 
       contract="IDNNService"> 
      <identity> 

(你可能會或可能無法確保12345端口被防火牆暢通)

然後使用url:http://localhost:12345/Derp(當然,從它安裝在同一臺機器上)來測試您的服務。

相關問題