我創建了一個非常基本的服務操作,需要將內容寫入我的數據庫。這項服務看起來如下:向移動客戶端公開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'的默認端點元素。這可能是因爲沒有找到適用於您的應用程序的配置文件,或者因爲在客戶端元素中找不到匹配此合同的端點元素。
我在做什麼錯?看起來這應該是一個非常簡單的事情。感謝您的幫助。