2012-03-28 72 views
0

我想在启用Silverlight的WCF服务中使用Spring.Net。我创建了一个服务“User.svc”并将其配置为与Spring.Net一起使用,我得到以下错误:如何将Spring.Net与支持Silverlight的WCF服务结合使用?

'/'应用程序中的服务器错误。 ------------------------------------------------- -------------------------------

Composition proxy target must implement at least one interface. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more 

关于错误的信息以及它在代码中的起源。

Exception Details: System.ArgumentException: Composition proxy target must implement at least one interface. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of 

可以使用下面的异常堆栈跟踪来识别异常。

你能帮我一下吗?下面列出了所有相关的文件。

User.svc

<%@ ServiceHost Language="C#" Debug="true" Service="Client.Web.WCFServices.User" CodeBehind="User.svc.cs" Factory="Spring.ServiceModel.Activation.ServiceHostFactory" %> 

User.svc.cs

[SilverlightFaultBehavior] 
[ServiceContract(Namespace = "http://Client.Web")] 
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
public class User 
{ 
    private string testdi = "abc"; 

[OperationContract] 
    public string Hello(string msg) 
    { 
     return msg; 
    } 

    [OperationContract] 
    public int GetUserFromFingerprint(string fpt) 
    { 
     return 1; 
    } 

    [OperationContract] 
    public string HelloSpring(string msg) 
    { 
     UserDao ud = new UserDao(); 
     Entities.User u = new Entities.User(); 
     u.Password = "abc"; 
     u.Group = new Entities.Group(); 
     ud.Save(u); 
     return this.testdi; 
    } 
} 

Spring.net配置文件

<object id="UserServiceHost" type="Spring.ServiceModel.Activation.ServiceHostFactoryObject, Spring.Services"> 
    <property name="TargetName" value="UserService" /> 
</object> 
<object id="UserService" singleton="false" type="Client.Web.WCFServices.User, Client.Web"> 
    <property name="testdi" value="qwe" /> 
</object> 

的Web.config

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name=""> 
       <serviceMetadata httpGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="false" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <customBinding> 
      <binding name="Client.Web.WCFServices.User.customBinding0"> 
       <binaryMessageEncoding /> 
       <httpTransport /> 
      </binding> 
     </customBinding> 
    </bindings> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
           multipleSiteBindingsEnabled="true" /> 
    <services> 
     <service name="UserService"> 
      <endpoint address="" binding="customBinding" bindingConfiguration="Client.Web.WCFServices.User.customBinding0" 
         contract="Client.Web.WCFServices.User" /> 
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 
</system.serviceModel> 

回答

0

该错误与Spring.Net或Silverlight无关。

WCF使用实现为接口的契约。你没有界面。

[ServiceContract] 
public interface ISampleInterface 
{ 
// No data contract is requred since both the parameter 
// and return types are primitive types. 
[OperationContract] 
double SquareRoot(int root); 

// No Data Contract required because both parameter and return 
// types are marked with the SerializableAttribute attribute. 
[OperationContract] 
System.Drawing.Bitmap GetPicture(System.Uri pictureUri); 

// The MyTypes.PurchaseOrder is a complex type, and thus 
// requires a data contract. 
[OperationContract] 
bool ApprovePurchaseOrder(MyTypes.PurchaseOrder po); 
} 

注意的ServiceContract和OperationContract的是在界面上,而不是在实现接口的类。

+0

嗨,我试过你的解决方案,但它没有帮助。如果我在User.svc.cs中删除了“Factory =”Spring.ServiceModel.Activation.ServiceHostFactory“”这行(将此服务置于Spring.Net的控制之外),则不会报告错误。 – 2012-03-29 04:27:09