开发者

WebGet method gives error 400 "Bad Request" in WCF REST Service Application [duplicate]

This question already exists: Closed 12 years ago.

Possible Duplicate:

Bad Request 400 while accessing WCF Rest service (WebGet)

Hi All,

Let me explain what I am doing with WCF rest service. Here's my code and config:

  1. IDNNService interface

    [ServiceContract]
    public interface IDNNService
    {
        [WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate = "hello/{Name}")]
        [OperationContract]
        string SayHello(string Name);
    }
    
  2. Service class that implements the interface

    public class DNNService : IDNNService
    {
        public string SayHello(string Name)
        {
            return string.Format("Hello {0}", Name);
        }
    }
    
  3. Configuration file

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

I am able to generate my SVC file that return correct information with wsdl

But 开发者_StackOverflow中文版the problem is when i try to access my actual method

http://localhost/DC560X_rest/DesktopModules/DNNCentric-RestService/Entities/DNNService.svc/rest/hello/prabhakar
  1. IE Dispaly "400 Bad Request"
  2. Firefox Display Blank Page

Please help me out. Thanks in advance


Your URL looks nutty as squirrel etc.

Set a URL for the service

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

(you may or may not have to ensure port 12345 is unblocked by your firewall)

then use the url: http://localhost:12345/Derp (of course, from the same machine it is installed on) to test your service.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜