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

后端 未结 16 2143
清歌不尽
清歌不尽 2020-12-04 15:42

EDIT:

After I modified the web.config and I don\'t get error that\'s good.... then I add a new page (html) and write this small code to consume the serv

相关标签:
16条回答
  • 2020-12-04 16:16

    After Add this to your web.config file and configure according to your service name and contract name.

    <behaviors>
       <serviceBehaviors>
          <behavior name="metadataBehavior">
             <serviceMetadata httpGetEnabled="true" />
          </behavior>
       </serviceBehaviors>
    </behaviors>
    <services>
       <service name="MyService.MyService" behaviorConfiguration="metadataBehavior">
          <endpoint 
              address=""   <!-- don't put anything here - Cassini will determine address -->
              binding="basicHttpBinding" 
              contract="MyService.IMyService"/>
          <endpoint 
              address="mex" 
              binding="mexHttpBinding" 
              contract="IMetadataExchange"/>
       </service>
    </services>
    

    Please add this in your Service.svc

    using System.ServiceModel.Description;
    

    Hope it will helps you.

    0 讨论(0)
  • 2020-12-04 16:17

    In my case I was getting this error because the option (HttpActivation) was not enabled.

    0 讨论(0)
  • 2020-12-04 16:19

    You need to add a metadata exchange (mex) endpoint to your service:

    <services>
       <service name="MyService.MyService" behaviorConfiguration="metadataBehavior">
          <endpoint 
              address="http://localhost/MyService.svc" 
              binding="customBinding" bindingConfiguration="jsonpBinding" 
              behaviorConfiguration="MyService.MyService"
              contract="MyService.IMyService"/>
          <endpoint 
              address="mex" 
              binding="mexHttpBinding" 
              contract="IMetadataExchange"/>
       </service>
    </services>
    

    Now, you should be able to get metadata for your service

    Update: ok, so you're just launching this from Visual Studio - in that case, it will be hosted in Cassini, the built-in web server. That beast however only supports HTTP - you're not using that protocol in your binding...

    Also, since you're hosting this in Cassini, the address of your service will be dictated by Cassini - you don't get to define anything.

    So my suggestion would be:

    • try to use http binding (just now for testing)
    • get this to work
    • once you know it works, change it to your custom binding and host it in IIS

    So I would change the config to:

    <behaviors>
       <serviceBehaviors>
          <behavior name="metadataBehavior">
             <serviceMetadata httpGetEnabled="true" />
          </behavior>
       </serviceBehaviors>
    </behaviors>
    <services>
       <service name="MyService.MyService" behaviorConfiguration="metadataBehavior">
          <endpoint 
              address=""   <!-- don't put anything here - Cassini will determine address -->
              binding="basicHttpBinding" 
              contract="MyService.IMyService"/>
          <endpoint 
              address="mex" 
              binding="mexHttpBinding" 
              contract="IMetadataExchange"/>
       </service>
    </services>
    

    Once you have that, try to do a View in Browser on your SVC file in your Visual Studio solution - if that doesn't work, you still have a major problem of some sort.

    If it works - now you can press F5 in VS and your service should come up, and using the WCF Test Client app, you should be able to get your service metadata from a) the address that Cassini started your service on, or b) the mex address (Cassini's address + /mex)

    0 讨论(0)
  • 2020-12-04 16:19

    Most of the time this happens due to less memory space. first check then try some other tricks .

    0 讨论(0)
  • 2020-12-04 16:21

    Add Serializable() before the type you expose

    Serializable()
    Public Class YourType
    

    Put Serializable into <>

    0 讨论(0)
  • 2020-12-04 16:21

    I have tried several solutions mentioned over web, unfortunately without any success. In my project, I have two interfaces(xml/json) for each service. Adding mex endpoints or binding configurations did not helped at all. But, I have noticed, I get this error only when running project with *.svc.cs or *.config file focused. When I run project with IService.cs file focused (where interfaces are defined), service is added without any errors. This is really strange and in my opinion conclusion is bug in Visual Studio 2013. I reproduced same behaviour on several machines(even on Windows Server machine). Hope this helps someone.

    0 讨论(0)
提交回复
热议问题