2010-04-27 5 views
0

J'essaie d'appeler un service WCF depuis mon application Silverlight 3. Mais ... en essayant de créer un 'service wcf activé par Silverlight' dans mon projet web, mon VS2008 se bloque lors de la création de l'élément (je pense que lors de l'édition du web.config). J'ai donc pensé: créons un service wcf 'normal', et modifions-le manuellement pour qu'il devienne un 'web service activé par Silverlight'. Donc, je me demandais quelles sont les différences, et deuxièmement: pourquoi y a-t-il une différence entre un service appelé à partir d'une application Silverlight et une application non Silverlight?SVC 'normal' versus 'Silverlight' SVC (WCF)

C'est ce que j'ai maintenant la liaison (j'ai un service sans un contrat d'interface, juste une classe directe exposée, pour commencer):

<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> 

Celui-ci ne fonctionne pas parce que quand je ajouter une référence à celle de l'application silverlight je reçois ces messages:

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, le service peut être démarré dans le navigateur, je reçois ceci:.

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

)

Répondre

0

Principalement ce qui est fait pour vous est:

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

donc un bon point de départ serait de convertir votre service à utiliser basicHttpBinding. Consultez Configuring Services Using Configuration Files pour plus d'informations sur les sections de web.config qui s'appliquent aux services.

Il peut y avoir une perte de flexibilité à l'utilisation des modèles comme décrit dans Silverlight enabled WCF Service Template is Bad Practice

Questions connexes