2010-09-26 62 views
0

我创建了一个非常基本的服务操作,需要将内容写入我的数据库。这项服务看起来如下:向移动客户端公开WebHttpBinding WCF服务

​​

ImyService定义如下所示:

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

此服务将同时暴露于WP7和iPhone客户端应用程序。正因为如此,我相信我需要使用webHttpBinding。这使我在我的web.config文件中使用以下设置:

<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应用程序都是同一解决方案的一部分。我可以在我的应用程序中成功添加对该服务的引用。当我运行应用程序时,引用该服务的页面会引发错误。错误说:

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

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

回答

1

您是否已将文件“ServiceReferences.ClientConfig”复制到Windows Phone 7项目中?这个文件在你的WCF项目中。另外,WP7客户端仅支持basicHttpBinding。因此,除非切换到basicHttpBinding

,否则您可能会看到一个空的“ServiceReferences.ClientConfig”文件