Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用windows 8.1手机应用程序连接到web服务时遇到问题_C#_Web Services_Windows Phone - Fatal编程技术网

C# 使用windows 8.1手机应用程序连接到web服务时遇到问题

C# 使用windows 8.1手机应用程序连接到web服务时遇到问题,c#,web-services,windows-phone,C#,Web Services,Windows Phone,这是我第一次做这样的事情,所以我可能听起来很愚蠢,但事情就是这样 这里是我应该连接到web服务的方法 public async void getWebData() { var uri = new Uri("http://localhost:9011/Service.svc?singleWsdl"); var httpClient = new HttpClient(); // Always catch network exceptions

这是我第一次做这样的事情,所以我可能听起来很愚蠢,但事情就是这样

这里是我应该连接到web服务的方法

public async void getWebData()
    {
        var uri = new Uri("http://localhost:9011/Service.svc?singleWsdl");
        var httpClient = new HttpClient();

        // Always catch network exceptions for async methods
        try
        {
            var result = await httpClient.GetStringAsync(uri);

            doSomething(result);
        }
        catch
        {
            // Details in ex.Message and ex.HResult.       
        }

        // Once your app is done using the HttpClient object call dispose to 
        // free up system resources (the underlying socket and memory used for the object)
        httpClient.Dispose();
    }
这是我在web.config文件中的配置信息,我认为我在其中正确添加了rest端点,因为我了解到您必须使用rest端点才能访问windows 8.1手机应用中的web服务

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService" />
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="WebHttpBinding_IService" />
  </webHttpBinding>
</bindings>
<services>
  <service name="WcfService.Service1" behaviorConfiguration="MyServiceBehavior">
    <endpoint address="http://localhost:9011/Service.svc?singleWsdl" name="rest"
      binding="webHttpBinding" bindingConfiguration="WebHttpBinding_IService" contract="WcfService.IService" />
    <endpoint address="http://localhost:9011/Service.svc?singleWsdl" name="soap"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService" contract="WcfService.IService" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">
      <!-- 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>
  <endpointBehaviors>
    <behavior name="jsonBehavior">
      <enableWebScript/>
    </behavior>
  </endpointBehaviors>
</behaviors>


那么,有谁能告诉我访问我的Web服务时做错了什么,因为我尝试的任何东西都不起作用…

有什么异常?我没有收到异常。我在结果行插入了一个断点,但它从未触及断点。您对C#和Web服务是新手吗?因为根据您的web.config,您应该使用代理类,但您可以在代码中直接访问wsdl。另一个建议是尝试不使用async并等待。遵循以下示例:可能是一个愚蠢的问题,但您确定可以从电话/模拟器中点击
localhost
?不知道它是否真的能识别。因为
localhost
总是
Me