我是新手,在实现与 Windows 应用程序和网站 WCF Web 服务的通信时遇到问题。它一直显示错误,我已经尝试了很多次。希望有人能帮帮我~~
网站
IApiService.cs
[ServiceContract]
public interface IApiService
{
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json)]
Boolean TestConnection();
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json)]
Boolean IsPhoneNumberListMatch(int pa, int pb);
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json)]
List<ClientPhoneModel> GetAllPhoneNumber(string pa);
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json)]
List<ClientRegistrationModel> GetAllNewRegistration(string pa);
}
网络配置
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="EndBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehavior" name="ApiService">
<endpoint address="basic" binding="webHttpBinding" contract="IApiService" behaviorConfiguration="EndBehavior"/>
</service>
<service behaviorConfiguration="ServiceBehavior" name="WebService">
<endpoint address="" binding="webHttpBinding" contract="IWebService" behaviorConfiguration="EndBehavior"/>
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
窗口应用
添加localhost:5151/ApiService.svc 作为服务参考
索引.cs
try {
Localhost.ApiServiceClient client = new Localhost.ApiServiceClient();
client.TestConnection();
}
catch(Exception ex) {
Log.Exception(ex);
}
应用程序配置
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost:5151/ApiService.svc" behaviorConfiguration="EndBehavior" binding="webHttpBinding" contract="Localhost.IApiService" name="ApiServiceClient" />
</client>
</system.serviceModel>
我能得到的最新错误是
Message :
Operation 'IsPhoneNumberListMatch' of contract 'IApiService' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.
Stack trace :
at System.ServiceModel.Description.WebHttpBehavior.TryGetNonMessageParameterType(MessageDescription message, OperationDescription declaringOperation, Boolean isRequest, Type& type)
at System.ServiceModel.Description.WebHttpBehavior.ValidateBodyStyle(OperationDescription operation, Boolean request)
at System.ServiceModel.Description.WebHttpBehavior.<>c__DisplayClass7.<>c__DisplayClassa.<GetRequestClientFormatter>b__4()
at System.ServiceModel.Description.WebHttpBehavior.<>c__DisplayClass7.<GetRequestClientFormatter>b__3()
at System.ServiceModel.Description.WebHttpBehavior.HideReplyMessage(OperationDescription operationDescription, Effect effect)
at System.ServiceModel.Description.WebHttpBehavior.GetRequestClientFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint)
at System.ServiceModel.Description.WebHttpBehavior.ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
at System.ServiceModel.Description.DispatcherBuilder.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime clientRuntime)
at System.ServiceModel.Description.DispatcherBuilder.BuildProxyBehavior(ServiceEndpoint serviceEndpoint, BindingParameterCollection& parameters)
at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose)
at System.ServiceModel.ChannelFactory.CreateFactory()
at System.ServiceModel.ChannelFactory.OnOpening()
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.ChannelFactory.EnsureOpened()
at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via)
at System.ServiceModel.ChannelFactory`1.CreateChannel()
at System.ServiceModel.ClientBase`1.CreateChannel()
at System.ServiceModel.ClientBase`1.CreateChannelInternal()
at System.ServiceModel.ClientBase`1.get_Channel()
at LoonTeleShopClient.Localhost.ApiServiceClient.TestConnection() in c:\Users\Kelvin\Documents\Visual Studio 2012\Projects\LoonTeleShopClient\LoonTeleShopClient\Service References\Localhost\Reference.cs:line 339
at LoonTeleShopClient.Index..ctor() in c:\Users\Kelvin\Documents\Visual Studio 2012\Projects\LoonTeleShopClient\LoonTeleShopClient\Index.cs:line 44
请帮帮我~~~万谢