C# 使用windows 8.1手机应用程序连接到web服务时遇到问题
这是我第一次做这样的事情,所以我可能听起来很愚蠢,但事情就是这样 这里是我应该连接到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
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
。