I want to create a web part that calls a .asmx from another domain. I know I can't do this client side only due to cross site scripting restrictions that browsers enforce, so it must be server side. How should I do this with a web part? Is it simple as adding the service reference to my project and when I deploy, all that info will go and work just fine?

And I don't want to use a Data View web part or anything, this would be a Visual Web Part created with Visual Studio 2010.

  • This question was mainly just a confirmation that this is still the recommended approach and that everything would be deployable via WSP still. – Shane Apr 13 '11 at 14:06

.asmx usually have to be added as a web service reference in visual studio.

VS will then generate all the stub classes in your project.

You may need to have a web part property to set the Url of the webservice if it differs in DEV/PROD environments.

The easiest solution is to ensure the visual web part is installed into the GAC, so you get full trust. Or you could do a custom CAS policy.

You should also check that your production server can make outbound web service calls and can resolve the hostname of the target server.

  • Also make sure that the SharePoint application pool account has enough permissions on the web server hosting the .ASMX to be able to actually call the service. – Dave Wise Apr 13 '11 at 2:26
  • Yep, all custom elements are installed in the GAC. Just wanted to make sure there were no special steps to do to make the stub classes generated deployable. We will config out the web service location. Thanks. – Shane Apr 13 '11 at 14:05

One thing to be aware of is, if this web service of yours is anonymous or require authentication.

Normal Classic Windows authentication cannot validate a request across domains (double hop). If you are using Kerberos and the web service web server is trusted for delegation this isnt an issue.

You can also work around this by supplying NetworkCredentials in code.

  • 1
    Or even better using the Secure Store Service (Single-Sign-On) to store the username/passwords and pass those using custom credentials – Wictor Wilen MCA MCM MVP Apr 13 '11 at 11:02
  • Good tip on the SSO option. – Shane Apr 13 '11 at 14:05
  • yeah we actually did that on my last project SSS rocks! – Anders Rask Apr 13 '11 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.