i'm trying to call a WCF service from my Silverlight 3 app. But... when trying to create a 'silverlight enabled wcf service' in my web project, my VS2008 crashes during creating the item (i think while editing the web.config).
So i thought: let's create a 'normal' wcf service, and manually edit it to be a 'silverlight enabled webservice'.
So i wondered what the differences are, and second: why is there a difference between a service called from a silverlight app and a non-silverlight app?
This is what i have now for the binding (i have a service without an Interface contract, just a direct class exposed, to begin with):
<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>
This one doesn't work because when i add a reference to 开发者_Go百科it from the silverlight app i get these 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., the service can be started in the browser, i get this:
svcutil.exe http://localhost:9599/GetNewData.svc?wsdl
)
Primarily what is done for you is:
Web.config is configured to use basicHttpBinding since Silverlight does not support ws*.
ASP compatibility mode: <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
So a good start would be to convert your service to use basicHttpBinding. Check out Configuring Services Using Configuration Files for more on the sections of web.config that apply to services.
There can be some loss of flexibility to using the templates as described in Silverlight enabled WCF Service Template is Bad Practice
It seemed that there was another problem at hand, it was answered here
can i use a generic list in a WCF called from silverlight?
精彩评论