简体   繁体   English

使用Visual Studio 10和C#消耗Web服务

[英]Consuming a web service using Visual Studio 10 and C#

I need to call a web service using Visual Studio and C#. 我需要使用Visual Studio和C#调用Web服务。 I have already created a configuration file and a client to call the service, but I keep getting an exception: 我已经创建了一个配置文件和一个客户端来调用该服务,但是我一直遇到异常:

System.ServiceModel.FaultException'1: Oracle Connection is not successful. System.ServiceModel.FaultException'1:Oracle连接失败。

As I have not really worked with ASP.NET applications and web services much, I am not sure how to fix this, and whether it's due to my mistake or because something is wrong with the created web service itself. 由于我还没有真正使用ASP.NET应用程序和Web服务,因此我不确定如何解决此问题,也不确定是由于我的错误还是所创建的Web服务本身存在问题。

I have used the following to call the service: 我使用以下方法来调用该服务:

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

GetInformation is the Web Service Name, with an input parameter ID of type string, and returns a data set of user name, surname, and age. GetInformation是Web服务名称,其输入参数ID为字符串类型,并返回用户名,姓氏和年龄的数据集。

This is the stack trace: 这是堆栈跟踪:

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()

FaultException FaultException

FaultExceptions in the WCF world are used as a method of communicating server errors/exceptions across the WCF channel. WCF世界中的FaultExceptions用作通过WCF通道传达服务器错误/异常的方法。

In your case, it appears as though the web service you are attempting to consume is having problems connecting to a required database. 在您的情况下,您似乎正在尝试使用的Web服务在连接到所需的数据库时遇到问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM