简体   繁体   中英

Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata. WCF Error

I have a requirement that a WCF service where only one method will return data as json. So, what I did is:

1) Created a service named as IAdmin and respective class Admin.svc

2) within the service there are multiple methods with [OperationContract] attribute.

3) The method which I want to return data in json has been written as:-

[OperationContract]
[WebGet(UriTemplate="/getDetails", ResponseFormat=WebMessageFormat.Json)]
Admin_UserDetails getUserDetails(int user_id);

4) In the config file I added the following:-

<service   name="VMS_WCF_Service.Service1"     behaviorConfiguration="VMS_WCF_Service.VMSBehavior"  >
    <host>
      <baseAddresses>
        <add baseAddress="http://xxx.xxx.xx.xx/<Folder Name>/Admin.svc"/>
      </baseAddresses>
    </host>
    <endpoint address="Admin.svc" binding="basicHttpBinding" contract="<Namespace>.IAdmin" bindingConfiguration="ServicesBinding" >
      <identity>
        <dns value="192.168.82.57"/>
      </identity>
    </endpoint>

    <!-- Added by Agnib | START -->
    <endpoint name="serv" address="ep1" binding="webHttpBinding" contract="<Namespace>.IAdmin" behaviorConfiguration="jsonBehavior" bindingConfiguration="ServiceBinding"></endpoint>
    <!-- Added by Agnib | END -->
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>

5) I also added:-

<bindings>
<webHttpBinding>
  <binding name="ServiceBinding"
             maxReceivedMessageSize="2147483647"
    maxBufferSize="2147483647" sendTimeout="00:10:00" >
      <readerQuotas
            maxArrayLength="2147483647"
            maxBytesPerRead="2147483647"
      maxDepth="2147483647"
      maxNameTableCharCount="2147483647"
      maxStringContentLength="2147483647" />
    </binding>
</webHttpBinding>
</bindings>

<behaviors>
<endpointBehaviors>
    <behavior name="jsonBehavior">
      <webHttp/>     
    </behavior>
  </endpointBehaviors>
</behaviors>

6) Finally, while running, I am getting the following error:-

Error: Cannot obtain Metadata from http://localhost:<port_no>/Admin.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:<port_no>/Admin.svc Metadata contains a reference that cannot be resolved: 'http://localhost:<port_no>/Admin.svc'. The requested service, 'http://localhost:<port_no>/Admin.svc' could not be activated. See the server's diagnostic trace logs for more information.HTTP GET Error URI: http://localhost:<port_no>/Admin.svc There was an error downloading 'http://localhost:<port_no>/Admin.svc'. The request failed with the error message:-- 

Server Error in '/' Application.

Operation 'GetPeopleByAssignmentAndStatus' of contract 'IAdmin' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Operation 'GetPeopleByAssignmentAndStatus' of contract 'IAdmin' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: Operation 'GetPeopleByAssignmentAndStatus' of contract 'IAdmin' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.] System.ServiceModel.Description.WebHttpBehavior.TryGetNonMessageParameterType(MessageDescription message, OperationDescription declaringOperation, Boolean isRequest, Type& type) +473 System.ServiceModel.Description.WebHttpBehavior.ValidateBodyStyle(OperationDescription operation, Boolean request) +140 System.ServiceModel.Description.WebHttpBehavior.ValidateBodyParameters(OperationDescription operation, Boolean request) +92 System.ServiceModel.Description.<>c__DisplayClass13.b__d() +105 System.ServiceModel.Description.<>c__DisplayClass10.b__c() +544 System.ServiceModel.Description.WebHttpBehavior.HideReplyMessage(OperationDescription operationDescription, Effect effect) +183 System.ServiceModel.Description.WebHttpBehavior.GetRequestDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) +382 System.ServiceModel.Description.WebHttpBeh avior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) +3356 System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +3301 System.ServiceModel.ServiceHostBase.InitializeRuntime() +65 System.ServiceModel.ServiceHostBase.OnBeginOpen() +34 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +50 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +310 System.ServiceModel.Channels.CommunicationObject.Open() +36 System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +91 System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +598[ServiceActivationException: The service '/Admin.svc' cannot be activated due to an exception during compilation. The exception message is: Operation 'GetPeopleByAssignmentAndStatus' of contract 'IAdmin' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped..] System.Runtime.AsyncResult.End(IAsyncResult result) +495736 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178 System.ServiceModel.Activation.ServiceHttpHandler.EndProcessRequest(IAsyncResult result) +6 System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +129


Version Information:ÿMicrosoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929 --.

I have looked for this in the internet and can understand that there are some issues in the configuration, but cannot be able to detect it.

Any help is appreciated.

Thanks.

Change <behavior name="jsonBehavior"> to:

<behavior name="jsonBehavior">
    <serviceMetadata httpGetEnabled="True"/>
</behavior>

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