Calling a external web service in a SharePoint 2013 WebPart

I need to call a external web service in SharePoint 2013 WebPart. The web service URL is "http://abr.business.gov.au/abrxmlsearchRPC/AbrXmlSearch.asmx".

I created a ASP.NET web application to test the functionality firstly.
I added a server reference as a Web reference for this web service and then using the web service call but received the "Unable connect to remote server" error.

I changed to use "HttpWebRequest" e.g.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("<service url>");

and then add a "webproxy" class as below:
WebProxy webProxy = new WebProxy("<proxy url>");  

Set the HttpWebRequest to use above proxy
request.Proxy = webProxy;

But I retrieved the "HTTP 401 Not Found" error message when try to get the response:
response=((HttpWebResponse)(webRequest.GetResponse()));  

So I decided to use default system proxy as below:
request.Proxy = WebRequest.GetSystemWebProxy();

Also added following line in web.config file:
 <system.net>
    <defaultProxy useDefaultCredentials="true">
      <proxy usesystemdefault="True" bypassonlocal="True" />
    </defaultProxy> 
 </system.net>

I can call Web service successfully now. However, the above code and settings not working in SharePoint environment.

So I have to changed settings as below:
 <system.net>
    <defaultProxy useDefaultCredentials="true">
     <proxy usesystemdefault="false" proxyaddress="<proxy url>" bypassonlocal="true" />
    </defaultProxy> 
 </system.net>

I removed the code "request.Proxy = WebRequest.GetSystemWebProxy();". But I received "Unable connect to server" error again. I verified the proxy URL and found out it points to a script file, and so I updated the proxy URL to only up to the site URL and then try to call Web service again. Working successfully!


Comments

  1. What URL did you use for your Proxy URL, was this the root site of the or the

    ReplyDelete
    Replies
    1. It's the proxy server URL in your IT environment. You can find it in the IE settings->connections.

      Delete

Post a Comment

Popular posts from this blog

Top JavaScript courses helping you develop SPFx webPart with ReactJS and AngularJS

Effective LLM Prompting skills

Enable the Microsoft Power BI report file type (.pbix) in SharePoint Search