Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 service like this:

 $("#btn12").click(function (event) {                 $.getJSON('http://localhost:3576/MyService.svc/GetCurrentUser', {},                 function (data) {                     alert(data);                 });                 //return false;             }); 

I see the following error in my FireBug:

http://localhost:3576/MyService.svc/GetCurrentUser 400 Bad Request 

Note: I have added html page on the same wcf project and running the project it self so I am assuming the service is also running ...

What might be wrong here?

END EDIT

I have just created a new wcf services and when I hit f5 from VS and I get this error in WCF Test Client window :

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

Error: Cannot obtain Metadata from http://localhost:3696/MobileService.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:3696/MyService.svc
Metadata contains a reference that cannot be resolved: 'http://localhost:3696/MyService.svc'.

There was no endpoint listening at http://localhost:3696/MyService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

Unable to connect to the remote server
No connection could be made because the target machine actively refused it 127.0.0.1:3696
HTTP GET Error
URI: http://localhost:3696/MyService.svc
There was an error downloading 'http://localhost:3696/MyService.svc'.
Unable to connect to the remote server
No connection could be made because the target machine actively refused it 127.0.0.1:3696

My config:

<behaviors>     <endpointBehaviors>         <behavior name="MyService.MyService">             <webHttp/>         </behavior>     </endpointBehaviors>     <serviceBehaviors>         <behavior name="metadataBehavior">             <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:2812/MyService.svc" />         </behavior>     </serviceBehaviors> </behaviors> <services>     <service name="MyService.MyService"               behaviorConfiguration="metadataBehavior">         <endpoint              address="http://localhost/MyService.svc"              binding="customBinding"             bindingConfiguration="jsonpBinding"              behaviorConfiguration="MyService.MyService"             contract="MyService.IMyService"/>     </service> </services> <bindings>     <customBinding>         <binding name="jsonpBinding">             <jsonpMessageEncoding/>             <httpTransport manualAddressing="true"/>         </binding>     </customBinding> </bindings> <extensions>     <bindingElementExtensions>         <add name="jsonpMessageEncoding" type="Microsoft.Ajax.Samples.JsonpBindingExtension, MyService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>     </bindingElementExtensions> </extensions> 
like image 585
Nick Kahn Avatar asked Mar 04 '11 21:03

Nick Kahn


1 Answers

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)

like image 84
marc_s Avatar answered Oct 11 '22 19:10

marc_s