向移动客户端公开 webHttpBinding WCF 服务 [英] Exposing a webHttpBinding WCF service to mobile clients

查看:28
本文介绍了向移动客户端公开 webHttpBinding WCF 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个非常基本的服务操作,需要将内容写入我的数据库.此服务如下所示:

I have created a very basic service operation that needs to write content to my database. This service looks like the following:

[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;
    }
  }
}

ImyService 的定义如下所示:

ImyService is defined as shown here:

[ServiceContract]
public interface ImyService
{
  [OperationContract]
  [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]
  MyServiceResult MyMethod(string p1, string p2);
}

此服务将公开给 WP7 和 iPhone 客户端应用程序.因此,我相信我需要使用 webHttpBinding.这导致我在 web.config 文件中使用以下设置:

This service will be exposed to both WP7 and iPhone client applications. Because of this, I believe I need to use webHttpBinding. This has caused me to use the following settings in my web.config file:

<system.serviceModel>      
  <behaviors>
    <endpointBehaviors>
      <behavior name="myServiceBehavior">
        <webHttp />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
      </behavior>
    </serviceBehaviors>
  </behaviors>

  <serviceHostingEnvironment 
    aspNetCompatibilityEnabled="true"   
    multipleSiteBindingsEnabled="true" />
  <services>
    <service name="myService">
      <endpoint address="" 
        behaviorConfiguration="myServiceBehavior" 
        binding="webHttpBinding" 
        contract="ImyService" />
    </service>
  </services>
</system.serviceModel>

服务和 WP7 应用程序都是同一个解决方案的一部分.我可以在我的应用程序中成功添加对服务的引用.但是,当我运行该应用程序时,引用该服务的页面会引发错误.错误说:

Both the service and WP7 app are part of the same solution. I can successfully add a reference to the service in my application. When I run the application though, the page that references the service throws an error. The error says:

在 ServiceModel 客户端配置部分中找不到引用合同MyServiceProxy.ImyService"的默认端点元素.这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素.

我做错了什么?看起来这应该是一件非常简单的事情.感谢您的帮助.

What am I doing wrong? It just seems like this should be a pretty straightforward thing. Thank you for your help.

推荐答案

您是否已将文件ServiceReferences.ClientConfig"复制到您的 Windows Phone 7 项目中?此文件位于您的 WCF 项目中.此外,WP7 客户端仅支持 basicHttpBinding.因此,除非您切换到 basicHttpBinding

Have you copied the file "ServiceReferences.ClientConfig" into your Windows Phone 7 project? This file is in your WCF project. Also, WP7 clients support basicHttpBinding only. So, you may see an empty "ServiceReferences.ClientConfig" file unless you switch over to basicHttpBinding

这篇关于向移动客户端公开 webHttpBinding WCF 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆