简体   繁体   中英

Discovered WCF service can't connect

I have a WCF service that I'm using to expose a data source (connected to via an EF model). My endpoint for some reason just stopped responding.

Up until my last changes I was just pulling the data at startup of my app. I'm now working on adding a subscribe/publish model on top of this so I can throw events when something hits the WCF service that results in the data changing (could do it in the client side but than I wouldn't catch other users changes).

I've been following the example from Microsoft: http://msdn.microsoft.com/en-us/library/ms752254.aspx and added the appropriate decorations to my service interface and implementations and added a subscribe/unsubscribe OperationContract etc. I than try to fire up the service and can't connect.

I than dropped the Service Reference from my client and tried to reattach. Here is the strange thing:

1) The WCF service builds and spins up in the developer host. 2) The Web.Config file wasn't touched. 3) The "Discover Services" option in the add service reference in vs 2012 sees the service but when I try to actually accept the discovered service it throws an error saying "error downloading metadata from the address.

I don't get how it can discover the service and then not be able to add it as a reference. I can see if I added the info myself but it found it.

As part of adding the publishing functionality I added the SessionMode.Required tag to the interface I'm not really sure how WCF handles sessions and haven't ever had to deal with sessions anywhere else in my coding (generally pull the data from the source and than process it locally has been the types of tools I needed to make in the past so no state needed to be persisted server side).

Any ideas?

my service web.config:


 <connectionStrings> <add name="TaskModelContainer" connectionString="metadata=res://*/TaskModel.csdl|res://*/TaskModel.ssdl|res://*/TaskModel.msl;provider=System.Data.SqlClient;provider 

connection string="data source=winhacker\\sqlexpress;initial catalog=TaskDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"/>

Note: Note sure what is going on with the formating most of the file doesn't show up in the preview but sufficience it to say it is the boilerplate one that gets autogenerated other than I added a connectionStrings section to like to my EF datapoint. If you want to see the file click on "edit" seems to show the source I copied though a bit formatted weird.

In the vast majority of cases where I have encountered this error, the issue has been a serialization issue on the server side; WCF will throw an exception about this during the metadata discovery phase, but VS does not display this exception.

In order to troubleshoot this problem, you need to add a diagnostics section to your web.config to capture the WCF information into a svclog file, then use Microsoft's Service Trace Viewer to examine the log and discover the actual exception being thrown.

The web.config section should look something like this:

  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="traceListener"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData="c:\log\WebTrace.svclog"  />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

and be added at the <configuration> level.

Once you have added the configuration and ensure that the specified directory exists, try adding the service reference again. This should cause the specified svclog file to be generated.

If you have VS installed on that machine, you should be able to just double-click the file in Windows Explorer and have the log opened automatically in the tool.

Once the log is opened, look down the list of activities in the left hand pane and click on the first one in red. Then, in the top right pane, select the first one that is red (or shows an exception, I forget which). You can then click on that to see the details, including exception information in the bottom right pane.

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