METRO访问WCF的方式很简单,就和访问Webservice是一样的
在项目中添加WCF的引用,在address中填写所请求的地址,点击GO,OK(如果你引用的地址没有错误的话,引用就已经完成了),然后代码中间就可以直接调用了
ServiceReference1.JokeClient client = new ServiceReference1.JokeClient(); var query = client.GetJokeListAsync(10); List<ServiceReference1.Joke> jokes = query.Result.ToList(); MessageDialog md = new MessageDialog(jokes[4].Title); md.ShowAsync();
另外WCF配置比较重要,这里贴上WCF的配置内容
<system.serviceModel> <bindings> <wsHttpBinding> <binding name="NoneSecurity" maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="false"> <readerQuotas maxStringContentLength="12000000" maxArrayLength="12000000"/> <security mode="None"/> </binding> </wsHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="JokeService.JokeServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="JokeService.JokeServiceBehavior" name="JokeService.JokeService"> <endpoint address="" bindingConfiguration="NoneSecurity" binding="wsHttpBinding" contract="IJokeService.IJoke"/> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> </system.serviceModel>
--------------------------------------------------------------------------------------------------------------------------------------------
顺势而为
顺势而为