如何在支持Silverlight的WCF服务中使用Spring.Net?

时间:2012-03-28 16:42:00

标签: c# wcf silverlight spring.net

我想将Spring.Net与支持Silverlight的WCF服务一起使用。我创建了一个服务“User.svc”并将其配置为与Spring.Net一起使用,我收到了这些错误:

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

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>

1 个答案:

答案 0 :(得分: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位于接口上,而不是在实现接口的类上。