Windows Phone 8设备调试无法正常工作

时间:2013-08-16 15:33:44

标签: wcf windows-phone-7 windows-phone-8 windows-phone

我试图让某些应用连接到WCF服务。除了在实际设备上进行调试外,一切工作都很顺利。它报告TimeOut异常。我没有在使用模拟器时遇到问题,一切都很好。

这是我的主页上的代码:

public partial class MainPage: PhoneApplicationPage
{
    // Constructor
    public MainPage()
    {
        InitializeComponent();
        ServiceReference1.WCFClient serviceClient = new ServiceReference1.WCFClient();

        serviceClient.LoadExamsAsync("Marco");
        serviceClient.LoadExamsCompleted += serviceClient_LoadExamsCompleted;


    }

    void serviceClient_LoadExamsCompleted(object sender, ServiceReference1.LoadExamsCompletedEventArgs e)
    {
        lls2.ItemsSource = e.Result; // longlistselector
    }
 }
来自IExams.cs的

[ServiceContract]
public interface IExams
{

    [OperationContract]
    List<LoadExamsResult> LoadExams();

}

来自Exams.svc.cs:

public class ExamsService : IExams
{
    public ExamsDataClassesDataContext data { get; set; }
    public ExamsService()
    {
        data = new ExamsDataClassesDataContext();
    }

    public List<LoadExamsResult> LoadExams(string un)
    {
        return data.LoadExams(un).ToList();
    }
}

LinqToSql类是自动创建的,我从Sql Server中的数据库调用存储过程..

这是我的web.config文件:

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="ConnectionString" connectionString="Data Source=Alex;Initial        Catalog=Ispiti;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
     <httpRuntime targetFramework="4.5" executionTimeout="1200"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false    before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the   value below to true.  Set to false before deployment to avoid disclosing exception  information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
         Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
   </system.webServer>

</configuration>

和我的ServiceReferences.ClientConfig

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="basicHttpBinding_IExams" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
                    <security mode="None" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://192.168.137.146:14584/Exams.svc" binding="basicHttpBinding"
                bindingConfiguration="basicHttpBinding_IExams" contract="ServiceReference1.IExams"
                name="basicHttpBinding_IExams" />
        </client>
    </system.serviceModel>
</configuration>

1 个答案:

答案 0 :(得分:0)

如果您的本地计算机上有WCF服务,则需要允许通过防火墙进行外部连接。此外,您需要将设备连接到PC的同一网络。即使这样,您也可以尝试使用PC IP而不是名称来连接服务(使用http://192.168.1.23/service而不是http://mypcname/service)。

相关问题