Wcf 与通过HTTP请求公开的服务交互

Wcf 与通过HTTP请求公开的服务交互,wcf,windows-phone-7,Wcf,Windows Phone 7,我有一个名为myService.svc的服务。此服务使用webHttpBinding绑定公开。原因是我需要能够从iPhone和JQuery接口调用该服务。据我所知,WP7仅直接支持依赖于SOAP消息的BasicHttpBinding。不幸的是,iPhone不直接支持SOAP 我的问题是,我不能使用WebClient或HttpWebRequest与使用webHttpBinding的服务交互吗。从概念上讲,我相信它会起作用,但实现有点暗指我。我定义了以下服务: [AspNetCompatibilit

我有一个名为myService.svc的服务。此服务使用webHttpBinding绑定公开。原因是我需要能够从iPhone和JQuery接口调用该服务。据我所知,WP7仅直接支持依赖于SOAP消息的BasicHttpBinding。不幸的是,iPhone不直接支持SOAP

我的问题是,我不能使用WebClient或HttpWebRequest与使用webHttpBinding的服务交互吗。从概念上讲,我相信它会起作用,但实现有点暗指我。我定义了以下服务:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(IncludeExceptionDetailInFaults = false)]
public class myService : ImyService
{
  public MyServiceResult MyMethod(string p1, string p2)
  {
    try
    {
      // Do stuff
      MyResponseObject r = new MyResponseObject();
      r.Property1 = DateTime.Now;
      r.Property2 = "Some other data";
      return r;
    }
    catch (Exception ex)
    {
      return null;
    }
  }
}

[ServiceContract]
public interface ImyService
{
  [OperationContract]
  [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]
  MyServiceResult MyMethod(string p1, string p2);
}
在我的WP7应用程序中,我使用以下代码:

string opUrl = "http://localhost:80/services/myService.svc";
Uri myServiceUri = new Uri(opUrl, UriKind.Absolute);

WebClient myServiceClient = new WebClient();
myServiceClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(myServiceClient_DownloadStringCompleted);
myServiceClient.DownloadStringAsync(myServiceUri);

private void myServiceClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
  if (e.Result == null)
    MessageBox.Show("null");
  else
    MessageBox.Show(e.Result);
}

当我执行此操作时,e.Result不为null。相反,返回了一堆HTML,告诉我使用svcutil.exe。我的问题是:1)如何使用webHttpBinding将此方法称为“MyMethod”?2) 如何传入参数?

您不必使用服务绑定。您不受SOAP的约束,仅格式化消息

您可以使用和。

请注意,手机上只支持异步请求