【问题标题】:'normal' SVC versus 'Silverlight' SVC (WCF)“正常” SVC 与“Silverlight” SVC (WCF)
【发布时间】:2010-04-27 08:21:20
【问题描述】:

我正在尝试从我的 Silverlight 3 应用程序调用 WCF 服务。 但是...当尝试在我的 Web 项目中创建“启用silverlight 的 wcf 服务”时,我的 VS2008 在创建项目期间崩溃(我认为是在编辑 web.config 时)。

所以我想:让我们创建一个“普通”wcf 服务,然后手动将其编辑为“启用silverlight 的网络服务”。

所以我想知道有什么区别,其次:为什么从 Silverlight 应用程序调用的服务和非 Silverlight 应用程序调用的服务有区别?

这就是我现在的绑定(我有一个没有接口契约的服务,只是一个直接暴露的类,开始):

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

    </system.serviceModel>

这个不起作用,因为当我从 silverlight 应用程序添加对它的引用时,我收到以下消息:

Warning 2   Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Exception has been thrown by the target of an invocation.
XPath to Error Source: //wsdl:definitions[@targetNamespace='']/wsdl:portType[@name='GetNewData']    C:\Silverlight\RadControlsSilverlightApp1\RadControlsSilverlightApp1\Service References\ServiceReference1\Reference.svcmap  1   1   RadControlsSilverlightApp1
Warning 3   Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='']/wsdl:portType[@name='GetNewData']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='CustomBinding_GetNewData']    C:\Silverlight\RadControlsSilverlightApp1\RadControlsSilverlightApp1\Service References\ServiceReference1\Reference.svcmap  1   1   RadControlsSilverlightApp1
Warning 4   Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='CustomBinding_GetNewData']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:service[@name='GetNewData']/wsdl:port[@name='CustomBinding_GetNewData']  C:\Silverlight\RadControlsSilverlightApp1\RadControlsSilverlightApp1\Service References\ServiceReference1\Reference.svcmap  1   1   RadControlsSilverlightApp1
Warning 5   Custom tool warning: No endpoints compatible with Silverlight 3 were found. The generated client class will not be usable unless endpoint information is provided via the constructor.  C:\Silverlight\RadControlsSilverlightApp1\RadControlsSilverlightApp1\Service References\ServiceReference1\Reference.svcmap  1   1   RadControlsSilverlightApp1

(ps.,服务可以在浏览器中启动,我明白了:

svcutil.exe http://localhost:9599/GetNewData.svc?wsdl

)

【问题讨论】:

    标签: wcf silverlight silverlight-3.0


    【解决方案1】:

    为您完成的主要是:

    Web.config is configured to use basicHttpBinding since Silverlight does not support ws*. 
    ASP compatibility mode: <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
    

    因此,将您的服务转换为使用 basicHttpBinding 是一个好的开始。查看Configuring Services Using Configuration Files 了解更多关于适用于服务的 web.config 部分的信息。

    使用Silverlight enabled WCF Service Template is Bad Practice中描述的模板可能会失去一些灵活性

    【讨论】:

      【解决方案2】:

      手头好像有别的问题,这里回答了

      can i use a generic list in a WCF called from silverlight?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-05-11
        • 1970-01-01
        • 2021-03-14
        • 1970-01-01
        • 2020-07-05
        • 1970-01-01
        • 2015-05-28
        • 1970-01-01
        相关资源
        最近更新 更多