简体   繁体   中英

WCF REST service doesnt work

I created simple WCF web service project and enable the soap and rest service on it.

The soap service works fine but I can't use the rest service and help page.

Here is how I did it:

  1. my web service class:

     [OperationContract] [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/InsertWithDate/personTypeName({personTypeName})/accessName({accessName})/firstName({firstName})/lastName({lastName})/nationalID({nationalID})/email({email})/userName({userName})/passwordHash({passwordHash})/genderName({genderName})/statusName({statusName})")] [Description("Description for GET /InsertWithDate")] string InsertWithDate(string personTypeName, string accessName, string firstName, string lastName, string nationalID, string email, string userName, string passwordHash, string genderName, string statusName); 
  2. my web.config file:

     <?xml version="1.0"?> <configuration> <appSettings> <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> <!-- (Log4net diagnostics) --> <add key="log4net.Internal.Debug" value="true"/> </appSettings> <system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5"/> </system.web> <system.serviceModel> <!-- Add Rest service --> <services> <service name="WcfWebService.TestWS" behaviorConfiguration="ServiceBehavior"> <!-- Use a bindingNamespace to eliminate tempuri.org. bindingNamespace="http://contoso.com/services" --> <endpoint address="soap" binding="basicHttpBinding" contract="WcfWebService.ITestWS"/> <endpoint address="rest" binding="webHttpBinding" behaviorConfiguration="http" contract="WcfWebService.ITestWS"/> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <!-- Web service behavior (All kind of web Services hast it) --> <behavior name="ServiceBehavior"> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> <!-- Rest service behavier) --> <endpointBehaviors> <behavior name="http"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> <protocolMapping> <add binding="basicHttpsBinding" scheme="https" /> </protocolMapping> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> <standardEndpoints> <webHttpEndpoint> <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/> </webHttpEndpoint> </standardEndpoints> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> <directoryBrowse enabled="true"/> </system.webServer> </configuration> 

Now when I try these pages:

  1. localhost:51850/TestWS.svc/help
  2. localhost:51850/TestWS.svc/InsertWithDate/help
  3. localhost:51850/TestWS.svc/InsertWithDate/personTypeName(10)/accessName(10)/firstName(mn)/lastName(mn)/nationalID(12)/email(a@asd.com)/userName(nvcvncm)/passwordHash(123)/genderName(male)/statusName(d)

The same page appears: Server Error in '/' Application.

thank you.

Update: there is no error: just this page: 在此处输入图片说明

不好意思,很抱歉:我完全忘记了我的REST服务的地址:休息,而且也为了启用帮助页面,我只是将<webHttp helpEnabled="true"/>到我的web.conf文件中。

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