我试图通过C#调用WebService,并且正在遇到障碍。我无法弄清楚为什么我无法进行此调用,我使用相同的方法调用其他服务,但是这个传递了一个数组,我认为这是问题...我尝试了许多不同的方法来使我的数组初始化,我认为它正常工作,但抛出的错误并不能告诉我哪个对象导致了这个问题......
public void addActionCall(SurveyUser tUser)
{
//Create Client Object
RCServicesSoapClient sClient = new RCServicesSoapClient();
//Create Action Array
ActionItem[] tAction = new ActionItem[2];
//Initialize first item in the array
tAction[0] = new ActionItem();
//Assign values to first item
tAction[0].ActionType = "permission to contact via email";
tAction[0].ActionDefinedValue = "no";
//Initialize second item
tAction[1] = new ActionItem();
//Assign values to second item
tAction[1].ActionType = "age (if given):";
tAction[1].ActionOpenValue = "33";
//create AddAction Response
AddActionResponseBody addActionResponse = new AddActionResponseBody();
//Call AddAction WebService
addActionResponse.AddActionResult = sClient.AddAction(tUser.Guid, "testinfo", "testinfo", tAction); //This is where it breaks
Console.WriteLine("Status Code: " + addActionResponse.AddActionResult.statusCode);
Console.WriteLine("Status Description: " + addActionResponse.AddActionResult.statusDesc);
Console.WriteLine("AddAction Test Complete - Press Enter to Continue");
Console.ReadLine();
}
有什么想法吗?
例外:
System.ServiceModel.FaultException was unhandled
HResult=-2146233087
Message=Server was unable to process request. ---> Object reference not set to an instance of an object.
Source=mscorlib
StackTrace:
Server stack trace:
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.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 WebServicesTesting.RCWS.RCServicesSoap.AddAction(AddActionRequest request)
at WebServicesTesting.RCWS.RCServicesSoapClient.WebServicesTesting.RCWS.RCServicesSoap.AddAction(AddActionRequest request) in C:\Users\chris.lovell\Documents\Visual Studio 2010\Projects\WebServicesTesting\WebServicesTesting\Service References\RCWS\Reference.cs:line 4686
at WebServicesTesting.RCWS.RCServicesSoapClient.AddAction(String GUID, String ClientCode, String Domain, ActionItem[] Action) in C:\Users\chris.lovell\Documents\Visual Studio 2010\Projects\WebServicesTesting\WebServicesTesting\Service References\RCWS\Reference.cs:line 4696
at WebServicesTesting.TestHarness.addActionCall(SurveyUser tUser) in C:\Users\chris.lovell\Documents\Visual Studio 2010\Projects\WebServicesTesting\WebServicesTesting\Program.cs:line 291
at WebServicesTesting.WebServicesTest.Main(String[] args) in C:\Users\chris.lovell\Documents\Visual Studio 2010\Projects\WebServicesTesting\WebServicesTesting\Program.cs:line 73
at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
AddAction方法:
public WebServicesTesting.RCWS.ActionItem AddAction(string GUID, string ClientCode, string Domain, WebServicesTesting.RCWS.ActionItem[] Action)
{
WebServicesTesting.RCWS.AddActionRequest inValue = new WebServicesTesting.RCWS.AddActionRequest();
inValue.Body = new WebServicesTesting.RCWS.AddActionRequestBody();
inValue.Body.GUID = GUID;
inValue.Body.ClientCode = ClientCode;
inValue.Body.Domain = Domain;
inValue.Body.Action = Action;
WebServicesTesting.RCWS.AddActionResponse retVal = ((WebServicesTesting.RCWS.RCServicesSoap)(this)).AddAction(inValue);
return retVal.Body.AddActionResult;
}