简体   繁体   English

禁止状态代码 403 无法在 wsdl Web 服务上使用 postAsync 方法对多部分数据进行编码?

[英]Status code 403 forbidden unable to encode multipartform data using postAsync method on wsdl webservice?

I am new in wsdl webservice I am working on abbyy flexicapture webservice to upload file in fexicapture and get data in xml.我是wsdl webservice 的新手我正在使用 abbyy flexicapture webservice 来上传 fexicapture 中的文件并获取 xml 中的数据。 Now main problem arises I will get data while my code is in debug mode ie on local machine but while I publish my code to remote server I will get 403 error while encoding data at postAsync method.现在主要问题出现了我将在我的代码处于调试模式时获取数据,即在本地机器上,但是当我将代码发布到远程服务器时,我将在 postAsync 方法中编码数据时收到 403 错误。 Abbyy flexicapture share one demo project https://help.abbyy.com/en-us/flexicapture/12/developer/unattendedexample by using that code I created one MVC application in which I successfully get data from flexicapture which is on server using window Authentication on my local machine. Abbyy flexicapture 分享了一个演示项目https://help.abbyy.com/en-us/flexicapture/12/developer/unattendedexample通过使用该代码我创建了一个 MVC 应用程序,在该应用程序中我成功地从使用 window 的服务器上的 flexicapture 获取数据在我的本地机器上进行身份验证。

I am sharing my error with you please find我正在与您分享我的错误,请找到

Error :-EXCEPTION OCCURRED:System.Net.Http.HttpRequestException Response status code does not indicate success: 403 (Forbidden).    at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at WebServices.Controllers.HomeController.<FileRequest>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at WebServices.Controllers.HomeController.<UploadFile>d__17.MoveNext() System.Net.Http.HttpResponseMessage EnsureSuccessStatusCode()  

Flexicapture and Webservice are on same IIS which is on remote server. Flexicapture 和 Webservice 位于远程服务器上的同一个 IIS 上。

Thanks in advance please help me on this.在此先感谢请帮助我。

private static async Task<HttpResponseMessage> FileRequest(FlexicaptureWebservice.FlexiCaptureWebServiceSoapClient service, string action,int objectType, int sessionId, int projectId, int batchId, int parentId, int objectId, int version, string streamName)
{

  var creds = CredentialCache.DefaultNetworkCredentials;

  if (!string.IsNullOrEmpty(service.ClientCredentials.UserName.UserName))
     creds = new NetworkCredential(service.ClientCredentials.UserName.UserName, service.ClientCredentials.UserName.Password);
     using (var handler = new HttpClientHandler { Credentials = creds })
     {                   
       using (var client = new HttpClient(handler))
       {
         var uri = service.Endpoint.Address.Uri;
         var content = new FormUrlEncodedContent(new Dictionary<string, string>
          {
            {"Action", action},
            {"objectType", objectType.ToString()},
            {"sessionId", sessionId.ToString()},
            {"projectId", projectId.ToString()},
            {"batchId", batchId.ToString()},
            {"parentId", parentId.ToString()},
            {"objectId", objectId.ToString()},
            {"version", version.ToString()},
            {"streamName", streamName},
           });

           var response = await client.PostAsync(uri.OriginalString.Replace("/API/v1/Soap","/FileService/v1").Trim(), content).ConfigureAwait(false);
           response.EnsureSuccessStatusCode();
           client.Dispose();
           return response;
        }
     }              
  }

I caused this error because of some authentication problem on server IIS.由于服务器 IIS 上的某些身份验证问题,我导致了此错误。 So on my local build it works fine but while I publish thing on IIS caused error所以在我的本地构建它工作正常但是当我在 IIS 上发布东西时导致错误

I publish my code to remote server I will get 403 error while encoding data at postAsync method.我将我的代码发布到远程服务器,在 postAsync 方法中编码数据时会出现 403 错误。

So To remove error I go to->application pool of IIS ->Advance setting->Identity->Add custom account where I put my server credentials that's it.因此,为了消除错误,我转到-> IIS 应用程序池-> 高级设置-> 身份-> 添加自定义帐户,我将服务器凭据放在那里。

Now I am able to send files on flexicapture.现在我可以在 flexicature 上发送文件了。 I hope this little change help some developer.我希望这个小小的改变能帮助一些开发者。

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

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