开发者

How to access Wcf?

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

How to access Wcf?

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&开发者_如何学Python#62;
      </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();
            }
        }



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.


I watched a video on WCF with this exact error and it was never explained. http://channel9.msdn.com/shows/Endpoint/Endpoint-Screencasts-Self-hosting-WCF-Services/

You need to have administrator privilages to host the WCF service.

To do this, right click on your project, add new item. Select application manifest file.

This will generate you a basic manifest file.

You need it to contain <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

The overall file (cut down) will look like this

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</asmv1:assembly>

You can bind this manifest to the compiled .exe file if you need to, or just leave it in the same directory as the compiled project output (the .exe file) You can tell if it works because VS2010 will ask to restart with administration priv's when you try to debug.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜