locked
Consume Web service using C# RRS feed

  • Question

  • User-1770640340 posted

    Hi All,

    I need to consume one web service in my C# application through Visual Studio.
    I have been provided one URL of web service and an Access Token for that.

    Kindly suggest me how do I consume in my App.

    Thanks
    Gautam

    Wednesday, August 29, 2018 11:44 AM

All replies

  • User475983607 posted

    There is not enough information in your post to provide an accurate solution.  You're best source of information is the services providers support documentation.   Generally, an access token is provided after successfully authenticating with a service.  It seems a bit odd that you have an access token unless you already wrote code to authenticate. 

    If this is an SOAP service then create a service reference using Visual Studio.

    https://msdn.microsoft.com/en-us/library/bb628652.aspx

    If this is a REST service then use HttpClient.

    https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client

    As mentioned above, the service support documentation should explain how to communicate with the service.

    Otherwise, post your source code.

    Wednesday, August 29, 2018 12:27 PM
  • User-1770640340 posted

    <g class="gr_ gr_73 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="73" data-gr-id="73">Hi ,</g>

    Thanks for the prompt reply.

    I can tell you what exactly the requirement is.

    Service URL - http://localhost:81/magento2-2.2.5/soap/default?wsdl&services=customerCustomerMetadataV1

    This is the SOAP service URL which I got from Magento application 

    Our requirement is to read customer using this URL into our C# project.

    I tried adding it in Visual Studio  - Reference -> Add Service Reference, but its throwing error while doing same.

    Error - 

    There was an error downloading '<g class="gr_ gr_360 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="360" data-gr-id="360">http</g>://localhost:81/magento2-2.2.5/soap/default?wsdl&services=customerCustomerMetadataV1/_vti_bin/ListData.svc/$metadata'.
    The request failed with HTTP status 400: Bad Request.
    Metadata contains a reference that cannot be resolved: 'http://localhost:81/magento2-2.2.5/soap/default?wsdl&services=customerCustomerMetadataV1'.
    The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was ''.
    The remote server returned an error: (401) Unauthorized.
    If the service is defined in the current solution, try building the solution and adding the service reference again. 

    So please suggest how to proceed.

    Thanks
    Gautam

    Wednesday, August 29, 2018 12:42 PM
  • User475983607 posted

    So please suggest how to proceed.

     It looks like you are trying to host the site on your localhost.  Contact Magento support for setup instructions as this is well beyond ASP.NET support.

    Wednesday, August 29, 2018 1:10 PM
  • User-1770640340 posted

    <g class="gr_ gr_114 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="114" data-gr-id="114">Hi ,</g>

    I am not trying to host the website, <g class="gr_ gr_55 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" id="55" data-gr-id="55">its</g> already hosted.

    I want to just consume this service <g class="gr_ gr_75 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="75" data-gr-id="75">url</g>, I checked with POSTMAN tool by providing token as <g class="gr_ gr_123 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="123" data-gr-id="123">http</g> <g class="gr_ gr_174 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="174" data-gr-id="174">header ,</g> there <g class="gr_ gr_173 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" id="173" data-gr-id="173">its</g> working okay.

    In Visual studio is there any way to add access token to service <g class="gr_ gr_255 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="255" data-gr-id="255">url</g>.

    Thanks
    Gautam  

    Wednesday, August 29, 2018 1:14 PM
  • User475983607 posted

    Hi ,

    I am not trying to host the website, its already hosted.

    I want to just consume this service url, I checked with POSTMAN tool by providing token as http header , there its working okay.

    In Visual studio is there any way to add access token to service url.

    Thanks
    Gautam  

    I do not know how to help you. The error message is pointing to localhost:81 not an external host.  You stated you are using a SOAP service but PostMan is a REST client.  These are two very different protocols.    

    I recommend contacting Magento support for assistance or Google.

    https://stackoverflow.com/questions/40099650/integrate-magento-api-v2-to-asp-net

    Wednesday, August 29, 2018 1:21 PM
  • Wednesday, August 29, 2018 2:04 PM