我有一个带有WCF Web服务的Silverlight应用程序。我在godaddy上托管我的数据库,并允许远程连接到数据库。当我运行我的项目,连接到远程数据库时,内容按原样加载。但是,在部署应用程序时,由于某种原因,Web服务未正确执行。它是连接到同一数据库的相同代码,但我什么都没得到。
我能够很好地浏览我的远程svc文件(访问mysite.com/mywebservice.svc)。
我可以使用以下代码从我的asp页面(而不是Web服务)获取部分数据:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string myConnectionString = ConfigurationManager.ConnectionStrings["SilverlightWebConnectionString"].ConnectionString;
using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(myConnectionString))
{
using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand())
{
cmd.CommandText = "SELECT htmlTitle FROM HtmlAttributes WHERE pageName='Home'";
cmd.Connection = con;
con.Open();
TitleText.Text = Convert.ToString(cmd.ExecuteScalar());
cmd.CommandText = "SELECT htmlDescription FROM HtmlAttributes WHERE pageName='Home'";
string description = Convert.ToString(cmd.ExecuteScalar());
DescriptionMetaText.Text = string.Format("<meta name=\"description\" content=\"{0}\" />", description);
con.Close();
}
}
}
}
因此,我知道这不是数据库或连接字符串的问题。我唯一的猜测是我的web.config文件中有一个属性,我没有正确设置。
以下是web.config文件的代码:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="SilverlightWebConnectionString" connectionString="Data Source=mySource; Initial Catalog=myCatalog; User ID=myId; Password='myPassword';" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="MySilverlightWebsite.Web.MyWebService.customBinding0">
<!--<binaryMessageEncoding />-->
<textMessageEncoding>
<readerQuotas maxStringContentLength="2147483647"/>
</textMessageEncoding>
<httpTransport />
</binding>
</customBinding>
</bindings>
<services>
<service name="MySilverlightWebsite.Web.MyWebService">
<endpoint address="" binding="customBinding" bindingConfiguration="MySilverlightWebsite.Web.MyWebService.customBinding0" contract="MySilverlightWebsite.Web.MyWebService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />