简体   繁体   中英

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. 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. 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.

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.

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. So on my local build it works fine but while I publish thing on IIS caused error

I publish my code to remote server I will get 403 error while encoding data at postAsync method.

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.

Now I am able to send files on flexicapture. I hope this little change help some developer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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