Search code examples
c#.netwcfvisual-studio-2008wcf-binding

How to access Wcf?


i try to get some data via WCF. İ created below app.config. But i face to face below

enter image description here

Large png:

http://i54.tinypic.com/mjb9j4.png



<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service  name="WcfServiceLibrary.OnDomainModels.Message">
        <endpoint address="http://127.0.0.1:8731/MessageSrv" binding="wsHttpBinding" contract="WcfServiceLibrary.OnDomainModels.IData">
          <identity>
            <dns value="127.0.0.1" />
          </identity>
        </endpoint>
        <!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />-->
        <host>
          <baseAddresses>
            <add baseAddress="http://127.0.0.1:8731/Design_Time_Addresses/WcfServiceLibrary.OnDomainModels/Message/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfServiceLibrary.OnDomainModels.MessageBehavior">
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True" />
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

Error:

URL could not record. Do not have permission to access this namespace for your action C#

My WCf code:


namespace WcfServiceLibrary.OnDomainModels
{
    [ServiceContract]
    public interface IData
    {
        [OperationContract]
        int GetData();
   }
}


   public class Message : IData
    {
  public int GetData()
        {
            using (entity MaintCtx = new entity ())
            {
                return MaintCtx.NonRoutineCard.Count();
            }
        }



Solution

  • You need to give proper access the user account in which the host is running under. Use netsh form the command prompt

    http://blogs.msdn.com/b/anirbanc/archive/2008/05/14/wcf-error-http-could-not-register-url-http-8000-your-process-does-not-have-access-rights-to-this-namespace.aspx

    You can run visual studio as admin but this does not always work. I had many issues with this on Windows 7.