使用Visual Studio 10和c#来消费web服务

本文关键字:web 服务 Visual Studio 使用 | 更新日期: 2023-09-27 18:03:22

我需要使用Visual Studio和c#调用web服务。我已经创建了一个配置文件和一个客户端来调用服务,但我一直得到一个异常:

System.ServiceModel。FaultException'1: Oracle连接不成功。

因为我没有真正使用过ASP。. NET应用程序和web服务很多,我不确定如何解决这个问题,以及这是由于我的错误还是因为创建的web服务本身有问题。

我使用了以下代码来调用服务:

ServiceReference.InformationClient client = new ServiceReference.InformationClient();
client.GetInformation("123");
client.close();

GetInformation是Web Service Name,其输入参数ID类型为string,并返回用户名、姓氏和年龄的数据集。

这是堆栈跟踪:

System.ServiceModel.FaultException`1 was unhandled
Message=Oracle Connection is not successful
Source=mscorlib
StackTrace:
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 ConsumingWebService.ServiceReference.IInformation.GetInformation(String ID)
   at ConsumingWebService.ServiceReference.InformationClient.GetInformation(String ID) in c:'users'user'documents'visual studio 2010'Projects'ConsumingWebService'ConsumingWebService'Service References'ServiceReference'Reference.cs:line 53
   at ConsumingWebService.Program.Main(String[] args) in c:'users'user'documents'visual studio 2010'Projects'ConsumingWebService'ConsumingWebService'Program.cs:line 13
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

使用Visual Studio 10和c#来消费web服务

FaultException

在WCF世界中,FaultExceptions被用作跨WCF通道通信服务器错误/异常的方法。

在您的情况下,似乎您试图使用的web服务在连接到所需数据库时出现问题。