Calling external web services in ASP.NET Atlas

I just received this ASP.NET Atlas question via direct email, so thought I'd answer it publically:

I have a web project that has a AutoCompleteExtender textbox. Everything works fine if my .asmx file is in the same project.

<atlas:AutoCompleteExtender runat="server" ID="CustomerList">
<atlas:AutoCompleteProperties Enabled="true"
MinimumPrefixLength="1"
ServicePath="NorthwindService.asmx"
ServiceMethod="AutoCompleteCustomerList"
TargetControlID="customer"/>
</atlas:AutoCompleteExtender>

But as soon as I move the .asmx file to another project and add a web reference to the web project the WebMethod isn't being fired.

<atlas:AutoCompleteExtender runat="server" ID="CustomerList">
<atlas:AutoCompleteProperties Enabled="true"
MinimumPrefixLength="1"
ServicePath="http://server2/App/NorthwindService.asmx"
ServiceMethod="AutoCompleteCustomerList"
TargetControlID="customer"/>
</atlas:AutoCompleteExtender>

Same Host but Different Applications

If the web service you're attempting to hit is on the same host (eg http://localhost/App1/MyPage.aspx calling http://localhost/App2/MyService.asmx) then your issue most likely revolves around the proxy generation.

One of the magic building blocks behind service references in Atlas is the generation of JavaScript proxies for them. Create a new web service in your Atlas application (eg http://localhost/MyApp/MyService.asmx) then take a look at the proxy Atlas generates for it (http://localhost/MyApp/MyService.asmx/js). If you add this "/js" suffix to a web service URL in a non-Atlas application you'll just get an error. If you need to call a non-Atlas application like this, look at the instructions below for using bridges.

Different Hosts

If the web service you're attempting to hit is not on the same host (eg http://server1/MyPage.aspx calling http://server2/MyService.asmx) then your issue is the result of a security restriction:

Other than linking to external resource files (for example, image files, CSS files, script files, and so on), browser applications are restricted to accessing resources available on their home server. However, there is a great variety of Web services available on the Web, and the restriction to a home server limits what can be returned within the scope of a browser application.

To circumvent this restriction (in a secure way) you need to use an Atlas bridge, as documented here:

http://atlas.asp.net/docs/atlas/doc/bridge/default.aspx

technorati tags: ,

7 comments

  1. Great post.

    I was a littly confused though with the Title and paragraph.
    Same host, different applications.
    “If the web service you’re attempting to hit is on the same host (eg http://localhost/App1/MyPage.aspx calling http://localhost/App2/MyService.asmx) then your issue most likely revolves around the proxy generation.”

    I think it should be
    Same hosts, different Atlas applications.

    As even if you have the same host but one application is an Atlas web application and the other is a Web Service application (non-atlas) then the web method will never be called.

  2. @Clayton – The title/paragraph refers to different ASP.NET applications on the same box … and how it wouldn’t work unless they were both Atlas applications because of the lack of proxy generation hooks.

  3. I have an atlas app and a web service running on the same host but are different applications. I have read your explanation and tried your example. My question is: How do I take a look at the proxy atlas creates? I can find no file with a /js suffix. Also, where do I put the reference to the webservice file? I tried putting it in the

  4. I found the answer. Yea!!. create your own proxy. Add a web service to your calling app. Put web methods in the proxy that will call the real methods in the external service. The javascript will call this local service, which it can do easily and the local service calls the external service from the server-side. I hope this can help someone.

  5. I have 2 computer in LAN. C1 is 192.168.1.2 and C2 is 192.168.1.3. Both use WindowXP and IIS. A webservice called DemoWS1 is built on C1 (ex: Hello world). I want to invoke that webservice from C2. When I add “web references”, I inputed the URL below: http://192.168.1.2/DemoWS1/Service1.asmx.
    But it hasn’t found that page.
    What happen? Please help… I want to know how to call external webservice?

Comments are closed.