.Net 4.0传递参数时WCF服务失败
我想从WCF测试客户端使用basichttpbinding端点来测试WCF服务。我可以测试我不无问题传递参数的方法,但是当我需要传递一个参数,我得到了以下错误:.Net 4.0传递参数时WCF服务失败
Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.
An error occurred while executing the command definition. See the inner exception for details.
Server stack trace: at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at IErouter.GetClientSearch(String surname, String forename, String street, String postcode) at ErouterClient.GetClientSearch(String surname, String forename, String street, String postcode)
由于这一事实,我可以调用参数的方法,这个错误对我没有意义。
[ServiceContract]
public interface IErouter
{
#region Client Search
[OperationContract]
SelectClientSearch_Result[] GetClientSearch(
string surname, string forename, string street, string postcode);
#endregion
#region Changes
[OperationContract]
ChangeForBlackBerry[] GetClientChanges(string blackberryPin);
[OperationContract]
bool AcceptChange(int changeId, string blackberryPin);
[OperationContract]
bool AcknowledgeChange(int changeId, string blackberryPin);
[OperationContract]
ChangeForBlackBerry[] GetManagerChangesForShiftType(string blackberryPin,
string date, int shiftTypeId);
[OperationContract]
ClientDetailChangeViewModel GetClientDetailChange(int changeId);
#endregion
#region Client Details
[OperationContract]
ClientDetailViewModel GetClientDetails(int clientId);
[OperationContract]
SelectUserLevel_Result GetUserLevel(string blackberryPin);
#endregion
#region Useful Contacts
[OperationContract]
SelectAdminCentreTelNo_Result[] GetAdminCentreTelNos();
[OperationContract]
string GetDutyEmail();
[OperationContract]
SelectDutyManager_Result[] GetDutyManagerTelNos();
[OperationContract]
string GetGhaHandyTelNo();
[OperationContract]
SelectHospitalNos_Result[] GetHospitalTelNos();
[OperationContract]
string GetICTTelNo();
[OperationContract]
string GetMAHMobileTelNo();
[OperationContract]
SelectMyManagerNo_Result[] GetMyManagerTelNo(string blackberryPin);
[OperationContract]
string GetNHSDirectTelNo();
[OperationContract]
string GetOOHEmail();
[OperationContract]
string GetOOHTelNo();
[OperationContract]
string GetOperationsEmail();
[OperationContract]
string GetOperationsTelNo();
[OperationContract]
string GetOtherHandyPersonTelNo();
[OperationContract]
SelectSWTelNos_Result[] GetSWTelNo();
#endregion
#region Gaurdian 24 Visit Monitoring
[OperationContract]
string StartVisitMonitoring(int clientId, int activityDuration,
string activityText, string blackberryPin);
[OperationContract]
string StopVisitMonitoring(int clientId, string activityId,
string blackberryPin);
#endregion
}
错误来自应用程序中的其他地方... WCF错误不是最大的! :)
可能是序列化错误 - 请检查您的返回类SelectClientSearch_Result是否具有[DataContract]或[Serializable]。
这可能是值得尝试添加以下到Web.config:
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://host:port"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
如果不工作,你可以尝试将上述和删除元素:从上次<host></host>
(想法链接我已链接)
只需将以下内容添加到web.config中即可。
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
我读过的网站是:
http://msdn.microsoft.com/en-us/library/aa702682.aspx
http://msdn.microsoft.com/en-us/library/ms731336.aspx
http://community.discountasp.net/showthread.php?t=7719
一个提到的WCF服务究竟表现得像一个ASMX服务,这是为什么我认为这可能是相关的。
编辑:
你能发布你的服务和数据合同吗? – scmccart 2010-12-01 16:42:10
啊,我之前没有看到这个,但是我看到“执行命令定义时发生错误”,你碰巧使用了实体框架吗? – scmccart 2010-12-01 16:59:37
什么是内部异常?你有没有在你的数据类(ClientDetailViewModel和其他)上设置[DataContract]属性 – 2010-12-01 17:14:44