C# 对SOAP Web服务的Web API调用返回;“无法连接”;错误

C# 对SOAP Web服务的Web API调用返回;“无法连接”;错误,c#,web-services,asp.net-web-api,C#,Web Services,Asp.net Web Api,我为我的Web API应用程序设置了IIS。我的Web API中的一个函数调用SOAP Web服务。当我尝试使用其他项目调用Web API时,它返回一个无法连接到远程服务器的错误 奇怪的是,当我在调试模式下运行我的Web API应用程序时,错误并没有显示出来,并且按照预期工作 下面是我如何调用Web API的大致草案: static async Task RunAsyncBlogs() { using (var client = new HttpClient()) {

我为我的Web API应用程序设置了IIS。我的Web API中的一个函数调用SOAP Web服务。当我尝试使用其他项目调用Web API时,它返回一个
无法连接到远程服务器的错误

奇怪的是,当我在调试模式下运行我的Web API应用程序时,错误并没有显示出来,并且按照预期工作

下面是我如何调用Web API的大致草案:

static async Task RunAsyncBlogs()
{


   using (var client = new HttpClient())
   {
       client.BaseAddress = new Uri("http://ph-lb-d12/my_webapi/");
       client.DefaultRequestHeaders.Accept.Clear();
       client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));

       var success = "";

       // HTTP GET
       HttpResponseMessage response = await client.GetAsync("api/Controller/DoAction");

                if (response.IsSuccessStatusCode)
                {

                    success = "yes";
                }
                else
                {
                    success = "no";
                }


    }
 }
接下来,我将介绍如何从web API解决方案调用web服务: 假设
GetXMLData
是API控制器调用的函数

public XmlDocument GetXMLData()
{

    var xmlRaw = "";
    XmlDocument xmldoc = new XmlDocument();
    WS.Service webService = new WS.Service();

    xmlRaw = webService.DoAction("TEST").OuterXml; //THIS IS WHERE THE ERROR OCCURS

    xmldoc.Load(xmlRaw);

    return xmldoc;

}
假设当Web API解决方案处于调试模式时,所有这些都可以工作。但当它不是。它返回以下内容:

<Error><Message>An error has occurred.</Message><ExceptionMessage>Unable to connect to the remote server</ExceptionMessage><ExceptionType>System.Net.WebException</ExceptionType><StackTrace> at cemws.Core.PLI.GetXMLFeed() in e:\micron\cem\PROTOTYPE\cemws\src\cemws\Core\PLI.cs:line 70    at cemws.Controllers.IntegrationController.GetPLIFeed() in e:\micron\cem\PROTOTYPE\cemws\src\cemws\Controllers\IntegrationController.cs:line 42    at lambda_method(Closure , Object , Object[] )    at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.&lt;&gt;c__DisplayClass10.&lt;GetExecutor&gt;b__9(Object instance, Object[] methodParameters)    at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()  at System.Web.Http.Controllers.ApiControllerActionInvoker.&lt;InvokeActionAsyncCore&gt;d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()  at System.Web.Http.Controllers.ActionFilterResult.&lt;ExecuteAsync&gt;d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()  at System.Web.Http.Dispatcher.HttpControllerDispatcher.&lt;SendAsync&gt;d__1.MoveNext()</StackTrace><InnerException><Message>An error has occurred.</Message><ExceptionMessage>A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
10.2.1.3:8080</ExceptionMessage><ExceptionType>System.Net.Sockets.SocketException</ExceptionType><StackTrace> at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)    at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket&amp; socket, IPAddress&amp; address, ConnectSocketState state, IAsyncResult asyncResult, Exception&amp; exception)</StackTrace></InnerException></Error>
发生错误。无法连接到e:\micron\cem\PROTOTYPE\cemws\src\cemws\Core\PLI.cs:cemws.Controllers.IntegrationController.GetPLIFeed()第70行中cemws.Core.PLI.GetXMLFeed()处的远程serverSystem.Net.WebException在e:\micron\cem\PROTOTYPE\cemws\src\cemws\Controllers\IntegrationController.cs:System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.c_u显示类别10.GetExecutorb_u9(对象实例,对象[]方法参数)的lambda_u方法第42行位于System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext,IDictionary`2参数,CancellationToken CancellationToken)
---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()上引发异常的上一个位置的堆栈结束跟踪在System.Web.Http.Controllers.ApiControllerActionInvoker.InvokeActionAsyncCored\uu 0.MoveNext()中
---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()上引发异常的上一个位置的堆栈结束跟踪在System.Web.Http.Controllers.ActionFilterResult.ExecuteAsyncd\uuu 2.MoveNext()中
---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()上引发异常的上一个位置的堆栈结束跟踪在System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncd\uuu 1.MoveNext()上发生错误。由于连接方在一段时间后未正确响应,连接尝试失败,或者由于连接的主机未能响应,建立的连接失败
10.2.1.3:8080System.Net.Sockets.SocketException位于System.Net.ServicePoint.ConnectSocketInternal的System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress SocketAddress SocketAddress)处(布尔连接失败、套接字s4、套接字s6、套接字和套接字、IP地址和地址、ConnectSocketState状态、IAsyncResult asyncResult、异常和异常)

你如何从api调用
GetXMLData
?控制器调用
GetXMLData
。它在调试模式下工作。但是当我使用IIS时,它不是
GetXMLData
wcf服务的一部分?不。哦,很抱歉我忘了提到wcf函数是什么。它是
webService.DoAction(“测试”).OuterXml;
-这会产生错误您的控制器中还有另一个
DoAction
,对吗?