(转)发布Silverlight+WCF程序到IIS后,客户端访问数据库失败的解决方案
转自url:http://greatverve.cnblogs.com/archive/2011/11/30/silverlight-wcf-pub.html
我们在编写Silverlight程序时,大多情况下都需要借助WCF来访问我们的后端数据库,在开发过程中访问数据库都是正常的,但是当把整个silverlight项目连同WCF发布到IIS上之后,会遇到这样一个问题:在host IIS的服务器上能够正常访问数据库,但是当通过client端执行程序时却无法访问数据库,也没有错误信息,调用页面都是正常的。
应该有很多人都遇到了这个问题,在网上也有很多关于这个问题的解决方法,但是绝大部分都是从跨域访问的角度来解决这个问题的,然后再尝试添加了clientaccesspolicy.xml和crossdomain.xml这两个配置文件,并且添加了IIS中MIME配置后,依然有很多人没有解决,我就是其中之一,花了一些时间研究了一下WCF的原理,最后重新对WCF进行了配置检查,更改了对WCF绑定和调用的方式,这才得以把问题彻底解决,下面和大家一起分享一下具体步骤。
检查你的ServiceReferences.ClientConfig文件,这个文件是你在Silverlight程序中添加服务引用时自动生成的,检查里面绑定WCF的方式是否为BasicHttpBinding,具体代码如下:
- <configuration>
- <system.serviceModel>
- <bindings>
- <basicHttpBinding>
- <binding name="BasicHttpBinding_Gxpt_Service" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
- <security mode="None"/>
- </binding>
- </basicHttpBinding>
- </bindings>
- <client>
- <endpoint address="http://localhost:9545/Gxpt_Service.svc" binding="basicHttpBinding"
- bindingConfiguration="BasicHttpBinding_Gxpt_Service" contract="GxptServiceReference.Gxpt_Service"
- name="BasicHttpBinding_Gxpt_Service" />
- </client>
- </system.serviceModel>
- </configuration>
在你的Web工程下找到web.config文件,同样检查里面的WCF配置信息,绑定方式是否为"basicHttpBinding"方式,并且契约的名称是否填写正确,其具体代码如下:
- <system.serviceModel>
- <behaviors>
- <serviceBehaviors>
- <behavior name="">
- <serviceMetadata httpGetEnabled="true" />
- <serviceDebug includeExceptionDetailInFaults="true" />
- <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
- </behavior>
- </serviceBehaviors>
- </behaviors>
- <bindings>
- <basicHttpBinding>
- <binding name="BasicHttpBinding_Gxpt_Service" maxBufferPoolSize="2147483647"
- maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
- <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647"
- maxDepth="2147483647" maxNameTableCharCount="2147483647"
- maxStringContentLength="2147483647" />
- </binding>
- </basicHttpBinding>
- </bindings>
- <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
- multipleSiteBindingsEnabled="true" />
- <services>
- <service name="PubilshTest.Web.Gxpt_Service">
- <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Gxpt_Service"
- contract="PubilshTest.Web.Gxpt_Service" />
- <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
- </service>
- </services>
- </system.serviceModel>
最后,修改一下你调用WebService的代码:
- BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
- binding.MaxReceivedMessageSize = int.MaxValue;
- binding.MaxBufferSize = int.MaxValue;
- GxptServiceReference.Gxpt_ServiceClient client = new GxptServiceReference.Gxpt_ServiceClient(binding, new EndpointAddress(
- new Uri(Application.Current.Host.Source, "../Gxpt_Service.svc")));
- client.GetDataAsync();
- client.GetDataCompleted += new EventHandler<GxptServiceReference.GetDataCompletedEventArgs>(client_GetDataCompleted);
OK,可以再重新编译之后发布一下,别忘了加上必不可少的clientaccesspolicy.xml和crossdomain.xml这两个文件,否则你是无法通过IP访问到WCF的。
希望你看完之后,烦恼多日的问题能够迎刃而解。
(转)发布Silverlight+WCF程序到IIS后,客户端访问数据库失败的解决方案的更多相关文章
- wampserver安装后 mysql 所有数据库丢失的解决方案
事情起源: 晚上十点客户紧急来电,说是网站全部瘫痪.同事登陆数据库一看,Mysql Workbench Database下一片空白.当时我们都傻了. 发现原因: 服务器环境是windows serve ...
- asp.net 发布程序到iis后无法连接到oralce数据库问题
在应用程序池里面,选中你的站点所使用的应用程序池->高级设置->启用32位应用程序->true
- win10下安装psql9,后无法访问数据库引擎
1.修改安装文件兼容性,并启动安装 2.安装后 修改psql control center快捷方式的启动文件兼容性 3.修改 start workgroup engine 快捷方式的启动文件兼容性 一 ...
- eclipse项目配置tomcat后浏览器访问不到项目解决方案
先把项目从tomcat溢出,并删除tomcat,然后再次导入 双击: 修改:
- mysql创建用户后无法访问数据库的问题
1.停止mysql服务器 sudo service mysql stop 2.启动mysql服务 sudo mysqld_safe --skip-grant-tables 3.登陆 mysql mys ...
- 部署nginx后无法访问数据库,查看www-error.log日志报错Class 'mysqli' not found in /usr/local/nginx/html/mysql.php on line 2
检查你的php-mysql包是否安装 [root@localhost nginx]# rpm -qa php-mysql 没有任何输出则没有安装,接下来用yum安装php-mysql yum -y i ...
- Asp.net Core 1.0.1升级到Asp.net Core 1.1.0 Preview版本发布到Windows Server2008 R2 IIS中的各种坑
Asp.net Core 1.0.1升级到Asp.net Core 1.1.0后,程序无法运行了 解决方案:在project.json中加入runtime节点 "runtimes" ...
- Web项目或WCF发布IIS后,如何通过VS2010调试
在做项目的时候,例如WCF服务一般都会将WCF服务承载于控制台应用程序,或者WinForm窗体应用程序,因为这样可以直接在服务代码上打断点,然后就可以调试了.但是项目已经发布了,当然这里我用的本机进行 ...
- Asp.Net 应用程序在IIS发布后无法连接oracle数据库问题的解决方法
asp.net程序编写完成后,发布到IIS,经常出现的一个问题是连接不上Oracle数据库,具体表现为Oracle的本地NET服务配置成功:用 pl/sql 等工具也可以连接上数据库,但是通过浏览器中 ...
随机推荐
- Swift建立栈的泛型结构体以及top()、push()、pop()定义函数的定义
首先可以使用swift定义Stack的结构体 //泛型表达 struct Stack<T> { var items = <T>() //定义栈顶函数,返回栈顶元素 mutati ...
- 面试题---PHP
1.PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言. 2.echo,print和print_r的区别: echo和print都可以做 ...
- apache https 伪静态
今天很是郁闷,配置了一个https成功了,但是伪静态不成功,经过多方面查看资料终于配置成功了: <VirtualHost *:443> DocumentRoot /var/www/juba ...
- 《C与指针》第十二章练习
本章例程 //12.3 #include <stdio.h> #include <stdlib.h> typedef struct NODE{ struct NODE *lin ...
- linq之将IEnumerable<T>类型的集合转换为DataTable类型 (转载)
在考虑将表格数据导出成excel的时候,网上搜的时候找到一个特别合适的公共方法,可以将query查询出来的集合转换为datatable 需引用using System.Reflection; publ ...
- FTP上传-封装工具类
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import ja ...
- FZU-2075 Substring(后缀数组)
Description Given a string, find a substring of it which the original string contains exactly n such ...
- facebook darkforest围棋ai测试
0.darkforest说明 darkforest是facebook田渊栋博士开发的深度学习围棋程序,2016的uec cup得了第二名(http://jsb.cs.uec.ac.jp/~igo/en ...
- DBA-mysql-init-password-5.7
1.Mysql5.7 Password; 查找临时密码:grep "A temporary password" /var/log/mysqld.log 修改临时密码:alter ...
- Python set集合类型操作总结
Python中除了字典,列表,元组还有一个非常好用的数据结构,那就是set了,灵活的运用set可以减去不少的操作(虽然set可以用列表代替) 小例子 1.如果我要在许多列表中找出相同的项,那么用集合是 ...