WCF服务在使用外部DLL的类时无法找到元数据

时间:2012-05-10 12:50:31

标签: wcf wcf-hosting

我正在创建一个WCF服务,用于将数据插入数据库。

当使用本地作用于接口和服务本身类的函数时,WCF服务正常运行,但是,当我使用外部DLL中的类时,它无法启动。

我确保DLL中的类具有所有必需的属性,但仍然无法运行该服务。

有什么想法吗?

编辑: 这是错误的功能

  public Dal_Users createProfile(DateTime dateOfBirth, string email, string firstname, bool genderIsMale, string lastname, string mphoneno, string nickname, string password, string pictureURL)
    {
        try
        {
            //generate new user object
            /////////////////////////start user metadata/////////////////////////////////////////
            Dal_Users newUser = new Dal_Users();
            newUser.DateOfBirth = dateOfBirth;
            newUser.Email = email;
            newUser.FirstName = firstname;
            newUser.GenderIsMale = genderIsMale;
            newUser.LastName = lastname;
            newUser.MPhoneNo = mphoneno;
            newUser.NickName = nickname;
            newUser.Password = password;
            newUser.ProfilePicture = pictureURL;
            //////////////////////////////end user metadata///////////////////////////////////////


            //insert user in database, call updateUsers without an ID
            newUser.UpdateUsers();

            return newUser;
        }
        catch (Exception ex)
        {
            return new Dal_Users();
        }
    }

DAL_Users类来自DLL,标记为DataContract

/// <summary>
/// this is the data access class for the table Users
/// </summary>
[DataContract]
public class Dal_Users

EDIT2:

My app.config looks like this 
 <system.serviceModel>
    <services>
      <service name="ProfileService.ProfileMgr">
        <endpoint address="" binding="wsHttpBinding" contract="ProfileService.IProfileMgr">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/ProfileService/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 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>

我收到的错误是

  

错误:无法从http://localhost:8732/Design_Time_Addresses/ProfileService/Service1/mex获取元数据如果这是您有权访问的Windows(R)Communication Foundation服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata上的MSDN文档:Exchange错误URI:http://localhost:8732/Design_Time_Addresses/ProfileService/Service1/mex元数据包含无法解析的引用:'http:// localhost:8732 / Design_Time_Addresses / ProfileService / Service1 / MEX”。 Receivera:InternalServiceFault由于内部错误,服务器无法处理请求。有关错误的更多信息,请在服务器上启用IncludeExceptionDetailInFaults(来自ServiceBehaviorAttribute或来自&lt; serviceDebug&gt;配置行为),以便将异常信息发送回客户端,或者根据Microsoft .NET打开跟踪Framework 3.0 SDK文档并检查服务器跟踪日志.HTTP GET错误URI:http://localhost:8732/Design_Time_Addresses/ProfileService/Service1/mex下载'http:// localhost:8732 / Design_Time_Addresses / ProfileService / Service1 / mex'时出错。请求失败,HTTP状态为400:错误请求。

2 个答案:

答案 0 :(得分:0)

如果您尝试将服务和服务合同移至外部程序集,则需要修改.svc文件以指向该程序集。

<%@ ServiceHost Language="C#" Debug="true" Service="FULLASSEMBLYNAMEHERE" %>

答案 1 :(得分:0)

尝试在true中将includeExceptionDetailInFaults设置为web.config,以便在请求MEX端点时看到生成的错误消息。

请参阅this SO post,它与您收到的错误相似( HTTP状态400:错误请求)。