Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess .asmx webservice cross domain and load results into cascading dropdown
    primarykey
    data
    text
    <p>I have 2 sites.</p> <p>I also have a webservice.</p> <p>You can see this in action when I load countrynames in the cascading dropdown on: <a href="http://www.mydomain.com/trouwlocaties/zoeken-uitgebreid" rel="nofollow noreferrer">http://www.mydomain.com/trouwlocaties/zoeken-uitgebreid</a></p> <p>However, the same webservice throws an error on: <a href="http://otherdomain.com/weddingvenues/search-advanced" rel="nofollow noreferrer">http://otherdomain.com/weddingvenues/search-advanced</a> As you can see the dropdown shows 'method error -1' and in my Chrome console I see: 500 (Internal Server Error), where the client tries to GET the .asmx service, where on toptrouwen it uses POST (which is as I believe what's supposed to happen and also more secure).</p> <p>This is the GetCountries webservice:</p> <pre><code>&lt;System.Web.Script.Services.ScriptService()&gt; _ &lt;System.Web.Services.WebService(Namespace:="http://tempuri.org/")&gt; _ &lt;System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)&gt; _ &lt;Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()&gt; _ &lt;ToolboxItem(False)&gt; _ Public Class geolocation '&lt;System.Web.Script.Services.ScriptService()&gt; _ '&lt;WebService(Namespace:="http://tempuri.org/")&gt; _ '&lt;WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)&gt; _ '&lt;Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()&gt; _ Inherits System.Web.Services.WebService &lt;WebMethod()&gt; _ Public Function GetCountries(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue() Dim values As New List(Of CascadingDropDownNameValue) Dim myConnection As SqlConnection = GetConnection() Dim cmd As New SqlCommand(String.Format("SELECT id,name as title FROM country order by title asc", Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName), myConnection) Try myConnection.Open() Dim reader As SqlDataReader = cmd.ExecuteReader Dim CountryName As String Dim CountryID As Integer While reader.Read CountryName = reader("title").ToString Int32.TryParse(reader("id"), CountryID) values.Add(New CascadingDropDownNameValue(CountryName, CountryID.ToString)) End While Catch ex As Exception Finally myConnection.Close() End Try Return values.ToArray End Function End Class </code></pre> <p>First I tried adding this to my web.config:</p> <pre><code>&lt;system.web&gt; &lt;webServices&gt; &lt;protocols&gt; &lt;remove name="Documentation"/&gt; &lt;add name="HttpGet"/&gt; &lt;add name="HttpPost"/&gt; &lt;/protocols&gt; &lt;/webServices&gt; &lt;/system.web&gt; </code></pre> <p>After doing that, I receiving this in my Chrome console:</p> <pre><code>Uncaught SyntaxError: Unexpected token &lt; </code></pre> <p>Where apparently the result was not interpreted as XML, but my guess is JSON. After some Google searches I believed this had to do with the MIME type, but I never found out how to change that to XML for this service.</p> <p>So I continued searching and found something else, I was reading these posts: <a href="http://social.msdn.microsoft.com/forums/en-us/asmxandxml/thread/F80BDA62-C87A-4BDA-8CB1-F2CFAD1C8891" rel="nofollow noreferrer">http://social.msdn.microsoft.com/forums/en-us/asmxandxml/thread/F80BDA62-C87A-4BDA-8CB1-F2CFAD1C8891</a> <a href="https://stackoverflow.com/questions/14053484/uncaught-syntaxerror-unexpected-token-in-jquery-ajax">Uncaught SyntaxError: Unexpected token &lt; -- in jQuery ajax</a></p> <p>Where apparently it might be a 'cross-domain issue'.</p> <p>So I ended up with creating these files:</p> <p><strong>clientaccesspolicy.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;access-policy&gt; &lt;cross-domain-access&gt; &lt;policy&gt; &lt;allow-from http-request-headers="*"&gt; &lt;domain uri="*"/&gt; &lt;/allow-from&gt; &lt;grant-to&gt; &lt;resource path="/" include-subpaths="true"/&gt; &lt;/grant-to&gt; &lt;/policy&gt; &lt;/cross-domain-access&gt; &lt;/access-policy&gt; </code></pre> <p><strong>crossdomain.xml</strong></p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"&gt; &lt;?xml version="1.0" ?&gt; &lt;cross-domain-policy&gt; &lt;allow-access-from domain="*" /&gt; &lt;allow-access-from domain="*.otherdomain.com" secure="false" /&gt; &lt;/cross-domain-policy&gt; &lt;configuration&gt; &lt;system.serviceModel&gt; &lt;bindings&gt; &lt;basicHttpBinding&gt; &lt;binding name="GetCountries" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"&gt; &lt;security mode="None" /&gt; &lt;/binding&gt; &lt;/basicHttpBinding&gt; &lt;/bindings&gt; &lt;client&gt; &lt;endpoint address="http://www.mydomain.com/geolocation.asmx" binding="basicHttpBinding" name="GeoLocation" /&gt; &lt;/client&gt; &lt;/system.serviceModel&gt; &lt;/configuration&gt; </code></pre> <p>In the first example link that user also added attributes bindingConfiguration="DashboardServiceSoap" and contract="DashboardService.DashboardServiceSoap", but I have no idea what I would have to fill in there for my case.</p> <p>I'm still stuck, I don't know what is the right track and how to configure my setup.</p> <p><strong>UPDATE 21-06-2013</strong></p> <p>Updated my web.config with:</p> <pre><code>&lt;system.webServer&gt; &lt;httpProtocol&gt; &lt;customHeaders&gt; &lt;add name="Access-Control-Allow-Origin" value="*" /&gt; &lt;add name="Access-Control-Allow-Headers" value="Content-Type" /&gt; &lt;/customHeaders&gt; &lt;/httpProtocol&gt; </code></pre> <p>I also tried the following 4 configurations:</p> <pre><code>&lt;System.Web.Script.Services.ScriptService()&gt; _ &lt;System.Web.Services.WebService(Namespace:="http://tempuri.org/")&gt; _ &lt;System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)&gt; _ &lt;Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()&gt; _ &lt;ToolboxItem(False)&gt; _ Public Class geolocation Inherits System.Web.Services.WebService </code></pre> <p><strong>Scenario 1 and 2 With this method definition:</strong></p> <pre><code>&lt;WebMethod()&gt; _ Public Function GetCountries(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue() </code></pre> <p><strong>Scenario 1: WITH protocols section in web.config</strong> </p> <pre><code>&lt;webServices&gt; &lt;protocols&gt; &lt;remove name="Documentation"/&gt; &lt;add name="HttpGet"/&gt; &lt;add name="HttpPost"/&gt; &lt;/protocols&gt; &lt;/webServices&gt; </code></pre> <p>Works correct on .nl domain Throws method error -1 on .com domain. Chrome Console shows: Uncaught SyntaxError: Unexpected token &lt; GetCountries:1</p> <p><strong>Scenario 2: WITHOUT protocols section in web.config</strong> </p> <p>Works correct on .nl domain Throws method error -1 on .com domain. Chrome Console shows: GET <a href="http://www.otherdomain.com/geolocation.asmx/GetCountries?knownCategoryValues=%22%22&amp;category=%22Country%22&amp;callback=Sys._jsonp0" rel="nofollow noreferrer">http://www.otherdomain.com/geolocation.asmx/GetCountries?knownCategoryValues=%22%22&amp;category=%22Country%22&amp;callback=Sys._jsonp0</a> 500 (Internal Server Error) ScriptResource.axd:7773</p> <p><strong>Scenario 3 and 4 with this method definition:</strong></p> <pre><code>&lt;WebMethod()&gt; _ &lt;ScriptMethod(UseHttpGet:=True, ResponseFormat:=System.ServiceModel.Web.WebMessageFormat.Json)&gt; _ Public Function GetCountries(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue() </code></pre> <p><strong>Scenario 3: WITH protocols section in web.config</strong></p> <pre><code>&lt;webServices&gt; &lt;protocols&gt; &lt;remove name="Documentation"/&gt; &lt;add name="HttpGet"/&gt; &lt;add name="HttpPost"/&gt; &lt;/protocols&gt; &lt;/webServices&gt; </code></pre> <p>Throws method error 500 on .nl domain. Chrome Console shows: POST <a href="http://www.mydomain.com/geolocation.asmx/GetCountries" rel="nofollow noreferrer">http://www.mydomain.com/geolocation.asmx/GetCountries</a> 500 (Internal Server Error) catcher.js:197 Throws method error -1 on .com domain in dropdown. Chrome Console shows: Uncaught SyntaxError: Unexpected token &lt; GetCountries:1</p> <p><strong>Scenario 4: WITHOUT protocols section in web.config</strong> </p> <p>Throws method error 500 on .nl domain. Chrome Console shows: Failed to load resource: the server responded with a status of 500 (Internal Server Error) Throws method error -1 on .com domain in dropdown. Chrome Console shows: GET <a href="http://www.otherdomain.com/geolocation.asmx/GetCountries?knownCategoryValues=%22%22&amp;category=%22Country%22&amp;callback=Sys._jsonp0" rel="nofollow noreferrer">http://www.otherdomain.com/geolocation.asmx/GetCountries?knownCategoryValues=%22%22&amp;category=%22Country%22&amp;callback=Sys._jsonp0</a> 500 (Internal Server Error) </p> <p>Also I'm not explicity calling the .asmx from script, I let the cascading dropdown do that work for me. Like so:</p> <pre><code>&lt;asp:DropDownList ID="ddlCountries" CssClass="textbox" AutoPostBack="true" runat="server"&gt;&lt;/asp:DropDownList&gt; &lt;cc1:cascadingdropdown ID="cddCountries" runat="server" Category="Country" Enabled="True" LoadingText="&lt;%$Resources:Glossary,loading %&gt;" PromptText="&lt;%$Resources:Glossary,country_choose %&gt;" ServiceMethod="GetCountries" TargetControlID="ddlCountries"&gt; &lt;/cc1:cascadingdropdown&gt; </code></pre> <p><strong>code-behind</strong></p> <pre><code>cddCountries.ServicePath = "http://www.mydomain.com/geolocation.asmx" </code></pre> <p>I don't know if the fact that I'm using these pre-defined elements have anything to do with my issue, and I could better call the .asmx service via script myself and fill the dropdowns. If so: I have no idea how to do so.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload