Statlight not recognizing the ServiceReferences.ClientConfig non-assembly file even after setting the build action to "embed as resource".

Apr 20, 2010 at 6:53 PM

Hi there,

I'm using MS Tests for unit testing a piece of functionality which is asynchronous. I have a file ( a non- assembly config file name "ServiceReference.ClientConfig") which describes the endpoint so that the client application knows where my service lives.

I have read in one of the post that just by making the "non assembly file" to embed as a resource file, Statlight will recognize this file and should work fine. However, the problem I'm facing is

if I make this non assembly file as "Content" then only it is copied intto xap file. If I make it "embed as Resource" or just as "Resource" it is throwing an error saying.....

"ServiceReference.ClientConfig" is necessary for the client to know what the service endpoints are and either you create this in the code or add it into xap file."

Scenario with MS Test framework for Silverlight:

The unit test works just fine if the "ServiceReference.ClientConfig" build action is "Content". No issues.

Scenario with Statlight framework for Silverlight:

The unit test fails with the error mentioned below.

"ServiceReference.ClientConfig" is necessary for the client to know what the service endpoints are and either you create this in the code or add it into xap file."

 

Coordinator
Apr 21, 2010 at 12:09 AM

Thank you for your detailed explanation of your issue.

The issue is because StatLight is the "Host" application. It then streams down your xap and loads each assembly into it's appdomain (if that's what they still call it in silverlight). This means that the only thing that can work with StatLight must live within an assembly. 

I have one potential solution that would enable StatLight to solve this generically. Namely - StatLight _could_ inspect your xap and if it sees a "ServiceReference.ClientConfig" - copy it into StatLight's host xap (temporarily). (This is only theory - I haven't tried it yet)

Would you please create an issue regarding this so we can track it?

Until then, I suggest you call the overloaded MyServiceClient(...) methods - specifying the ABC's (Address, Binding, Contract) manually.

Hope this helps.

Apr 21, 2010 at 6:34 PM

Hi staxmanade,

I had even wanted to share this information to you about the scenarios' I tried.

Scenario 1:

Made the "ServiceReferences.ClientConfig" set to "Resource". The actual file (ServiceReferences.ClientConfig) was never copied into Xap. Manually copied and thought it might work. But it's not working.

The reason, I thought could be because, since the dlls' are now available in the application domain, after debugging, I found that the xapItems only contained the the assembly files loaded but not the config file. 

Scenario 2:

I deployed the "ServiceReferences.ClientConfig" file in the Application.Manifest file as one of the deployment parts. But this time made the assembly source = "string". Still no luck.

 

Lastly, when you said, " copy it into StatLight's host xap (temporarily)." I see the xap files with NOV, DEC and so on. Do I need to copy this config file into all of them or the latest xap file?

As of now, let me try this option mentioned and I will get back to you.

 

Thanks for your help.

 

Apr 21, 2010 at 7:29 PM

Also, tried the scenario where in  the host xap which resides in the clientBin of my asp.net web project and added this file into the xap archive. Still statlight is not able to recognize this file.

I can't use the overloaded method for my ServiceClient as this ServiceClient I'm using is from CSLA which only provides me to use the object parameter and a async-Callback to handle it.

We are using the CSLA for our business logic layer and also for the silverlight and somewhere down the lane, the "ServiceReference.ClientConfig" is being used by the CSLA framework to read those endpoints value and talk to the service.

Henceforth, I was trying out some easy options if my config file is in the xap and somehow the statlight takes care of loading this non-assembly into the in-memory and at the time of running the test cases, it uses this file to run the wcf service task.

One more thing, this config file only that if we make it as a "Content", the xap file gets the copy of the config file. Otherwise apart from this build action, none of them copies the config file over to the xap file.

Don't know if we can make the config file embed as a "Resource" and still copy it over to the xap file and if it works. [ Manually trying this, the efforts were in vain.]  :(

 

Regards,

CodePlexUser

Coordinator
Apr 21, 2010 at 9:50 PM

Sorry - I'm not quite understanding where you are at?

Just to Clarify - I'm going under the assumption you are using the Microsoft.Silverlight.Testing.dll? (Or are you using UnitDriven?)

If using the MSTest assembly - what version? I'm denoting each version in statlight by the monthYear it was deployed (November2009) is the nov 2009 release of the toolkit.

Drop your config  into the xap that corresponds with the StatLight.Client.For.{???}.xap. (or is that partially what you said you tried in your previous post? i'm not sure I understand what you did there).

I don't know the default behavior - when you have a service reference config - does it create an entry in the AppManifest?

If it does - try copying that entry into the StatLight.Client.For...xap AppManifest and add the clientconfig to the xap. (see if that helps?)

 

Apr 22, 2010 at 2:22 PM

Hi Staxmanade,

I'm not using UnitDriven. The version of statlight client I'm running is on

 StatLight - Version 0.9.3631
Copyright (C) 2009 Jason Jarrett
All Rights Reserved.

  [TestMethod]
        [Asynchronous]
        public void TestGetUser()
        {
            ClxUser.GetUser("Admin", (o, e) =>

             {
                if (e.Error == null && e.Object != null)
                {
                     Assert.AreEqual("System", ((ClxUser)e.Object).First.ToString());
                }
                EnqueueTestComplete();
            });
        }

Now, the code highlited in bold, is what internally making a call to the CSLA based business logic layer. In CSLA, there is a DataPortal class which handles the asynchronous operations. It returns a callback method for us to handle it. And that part is nothing but

                 if (e.Error == null && e.Object != null)
                {
                     Assert.AreEqual("System", ((ClxUser)e.Object).First.ToString()); 

                       // Internally calls the data portal instance to asynchronously fetch the e.Object(Ex. ClxUser)

                       //The CSLA framework uses the "ServiceReference.ClientConfig" file to read the endpoints.
                }

Internally, the ServiceReference.ClientConfig looks like this....

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IWcfPortal" closeTimeout="00:10:00"
                    openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
                    maxBufferSize="10000000" maxReceivedMessageSize="10000000" />
                <binding name="BasicHttpBinding_IWcfPortal1" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
                    <security mode="None" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:6000/WcfPortal.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IWcfPortal" contract="WcfPortal.IWcfPortal"
                name="BasicHttpBinding_IWcfPortal" />
            <endpoint address="http://localhost:6000/WcfPortal.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IWcfPortal1" contract="DataPortalServiceReference.IWcfPortal"
                name="BasicHttpBinding_IWcfPortal1" />
        </client>
    </system.serviceModel>
</configuration>

My Test xap file is named "SivlerlightTestApln.xap"

This file is being used by the CSLA DataPortal class to fetch the endpoints. As you mentioned, to use the overloaded method, there isn't one which I can use it to override it.

Statlight needs this config file as a "Resource". By doing so, I can't copy the file into the xap file ("SivlerlightTestApln.xap"). This is because, the copy of the config file is only made into the xap if you make the "ServiceReference.ClientConfig"  marked as "Content" in the build action of that file. This is what I observe at the time when the xap package is being created from the output window.

So answering your questions posted,

I have not used UnitDriven test framework. But used the CSLA for business logic and silverlight application.

Used the MS Tests as a tool to run the unit tests under the MS Silverlight Unit Test Framework.

Using Statlight "November 09 Release".

I hope I have conveyed you to get the detailed picture of what I'm trying to accomplish.

Again, thanks for you timely help.

CodePlexUserOne.

 

Coordinator
Apr 22, 2010 at 5:37 PM

OK - I got a spike to work out with your similar scenario...

The following link is to a zip that has a test project, web project, along with a trunk build of StatLight (Only change (special to your needs) is the ServiceReference.ClientConfig was placed inside the StatLight.client.for.November2009.xap).

I'd recommend using the trunk anyway (I've made a ton of improvements since my last release, and am trying to finalize up a 1.0 release).

You can download the link by going to 

Inside of the zip are some specific notes of things I had to specifically change/do to make it work out.

http://cid-c0f357e4555270e7.skydrive.live.com/embedicon.aspx/Public/ServiceReference.ClientConfig.Spike.zip

Hope this helps.

Apr 22, 2010 at 8:07 PM

Hi Staxmanade,

I sincerely thank you for all the efforts you took for answering these posts.

Let me take this effort more to incorporate on the same guidelines.

 

Thanks once again.

 

CodePlexUser.

Coordinator
Apr 22, 2010 at 9:59 PM

Ok. I've made a change to StatLight to support your scenario out of the box...

StatLight will now inspect your Xap - if it finds the ServiceReference.ClientConfig it will re-write the host StatLight xap and add your config on the fly.

Go download the master trunk - run the release.bat build (FYI: the full release build is having issues on a 64bit machine) Let me know if this works for you.

Coordinator
Apr 25, 2010 at 6:07 AM

Any luck resolving your issue here? (specifically any knowledge that can be contributed back to the project)

Apr 4, 2011 at 4:59 PM

I am having this issue with the current release where it does not seem to honor my ServiceReferences.ClietnConfig file.  In this file I have client endpoint addresses (I am running everything locally), but when running StatLight it is not finding these.

            <endpoint address="http://localhost:2793/InstrumentationServices/TestInstrumentationWebService.asmx"
                      binding="basicHttpBinding"
                      bindingConfiguration="TestInstrumentationWebServiceSoap"
                      contract="TestInstrumentationWebServices.TestInstrumentationWebServiceSoap"
                      name="TestInstrumentationWebServiceSoap" />

Test Namespace:  Bsi.Build2Win.Silverlight.Tests
Test Class:  IUC25_HandleUnhandledError_Tests
Test Method: A2_1_ErrorReportCouldNotBeSent
Exception Message:
System.ServiceModel.CommunicationException: An error occurred while trying to make a request to URI
'http://instrumentationservices/TestInstrumentationWebService.asmx'. This could be due to attempting
 to access a service in a cross-domain way without a proper cross-domain policy in place, or a polic
y that is unsuitable for SOAP services. You may need to contact the owner of the service to publish
a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error
may also be caused by using internal types in the web service proxy without using the InternalsVisib
leToAttribute attribute. Please see the inner exception for more details. ---> System.Security.Secur
ityException ---> System.Security.SecurityException: Security error.

Is there another place this is defined?

Coordinator
Apr 4, 2011 at 8:48 PM

jmullins - Try this. Run StatLight again with the --webserveronly flag. Then open up your favorite http monitoring tool (firefox/firebug) fiddler etc. Go open the URL given to you in the console window. Monitor the http traffic. Attempt to diagnose where the service request is happening and failing to call.

The crossdomain file must (i believe) exist on both sides. StatLight has a very wide open cross domain file.  https://github.com/staxmanade/StatLight/blob/master/src/StatLight.Core/Resources/CrossDomain.xml

If that doesn't help, attempt to download just the xap by itself. You should then be able to un-zip it and insepect it's contents. It should have included your ServiceReferences.clientconfig file.

Let me know if this helps.

Apr 5, 2011 at 1:21 PM

Looking at fiddler I get the following:

<!-- .REQUEST { font: 8pt Courier New; color: blue;} .RESPONSE { font: 8pt Courier New; color: green;} -->GET /clientaccesspolicy.xml HTTP/1.1
Accept: */*
Referer: http://localhost:8887/StatLight.Client.Harness.xap
Accept-Language: en-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDR; .NET4.0C; .NET4.0E)
Host: instrumentationservices
Proxy-Connection: Keep-Alive

HTTP/1.1 502 Fiddler - DNS Lookup Failed
Content-Type: text/html
Connection: close
Timestamp: 09:13:53.320

Text View: DNS Lookup for instrumentationservices failed. The requested name is valid, but no data of the requested type was found   

I did download the source and even built our config files in the tool, but no luck with that.  Looking at the xap has the config files.

So looking at the above fiddler info, it is trying to do DNS?  This is all on a single local host. 

Any experience with the DNS error above?

Coordinator
Apr 5, 2011 at 2:10 PM

I might be reading this wrong, but it looks like the failure is happening when trying to access the Host: instrumentationservices and requesting the file /clientaccesspolicy.xml? Do you have your external web service up and running at that location, and is it exposing a /clientaccesspolicy.xml?

Apr 5, 2011 at 2:32 PM

Yes, that is what it looks like.  So what I thought the problem was is the host definition.  It should be localhost:PORT as defined in the ServiceReferences.ClientConfig

http://localhost:2793/InstrumentationServices/TestInstrumentationWebService.asmx

This is a local build of our product, not a product install running under IIS.

I use the .Web->AutomatedTests.aspx to run our automation currently

Coordinator
Apr 5, 2011 at 2:51 PM

Does this mean you figured out your problem? Or are you still having troubles?

Apr 5, 2011 at 2:53 PM

Still having problems - that is just my opinion, I do not know how to get it to call the URL with the localhost defined correctly.

Coordinator
Apr 5, 2011 at 3:06 PM

The following link is an example of how I have a powershell script start a web service in a cassini instance, call StatLight passing in a QueryString containing the port to use. https://github.com/staxmanade/StatLight/blob/master/default.ps1#L730

And then inside the test, we pull the querystring and get the port to call the web service. https://github.com/staxmanade/StatLight/blob/master/src/StatLight.RemoteIntegration/StatLight.ExternalWebTest/Tests.cs#L19

Hope the above can help you.

What does the code look like that you are using to call an external web service?

Apr 5, 2011 at 3:49 PM

We have created the following (only contains a single example method per cs, but I hope it is enough to see the chain) Basically we use instrumentation to simulate web failures, email, reading log files, specific product functionality like delete users, set values, etc.:

Reference.cs

//
// This code was auto-generated by Microsoft.Silverlight.ServiceReference, version 4.0.50401.0
//

namespace Bsi.Build2Win.Instrumentation.TestInstrumentationWebServices {
    using System.Runtime.Serialization;

    public partial class InstrumentedEmailSettingsDto : object, System.ComponentModel.INotifyPropertyChanged {
       
        private string EmailAddressField;
       
        private bool SimulateFailureField;
       
        private bool EmailDisabledField;
       
        [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false)]
        public string EmailAddress {
            get {
                return this.EmailAddressField;
            }
            set {
                if ((object.ReferenceEquals(this.EmailAddressField, value) != true)) {
                    this.EmailAddressField = value;
                    this.RaisePropertyChanged("EmailAddress");
                }
            }
        }

We have TestInstrumentationDataStore.cs using Bsi.Build2Win.Instrumentation.TestInstrumentationWebServices;

namespace Bsi.Build2Win.Silverlight.Tests
{
    /// <summary>
    /// Data store to manage persistence of test instrumentation settings and
    /// operations.
    /// </summary>
    public class TestInstrumentationDataStore
    {
        #region Fields

        static InstrumentedEmailSettingsDto clientEmailSettings = new InstrumentedEmailSettingsDto();
        static InstrumentationServerErrorSettings clientServerErrorSettings = new InstrumentationServerErrorSettings();
        static int pendingPresentationServiceRequests = 0;

        #endregion

        #region Construction

        /// <summary>
        /// Initializes a new instance of the <see cref="TestInstrumentationDataStore"/> class.
        /// </summary>
        public TestInstrumentationDataStore()
        {
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets the pending presentation service requests.
        /// </summary>
        /// <value>The pending presentation service requests.</value>
        public static int PendingPresentationServiceRequests
        {
            get
            {
                return pendingPresentationServiceRequests;
            }
        }

        /// <summary>
        /// Gets the current client email settings.
        /// </summary>
        /// <value>The client email settings.</value>
        public static InstrumentedEmailSettingsDto ClientEmailSettings
        {
            get
            {
                Contract.Ensures( Contract.Result<InstrumentedEmailSettingsDto>() != null );
                return clientEmailSettings;
            }
        }

         #region Methods

       /// <summary>
        /// Saves the email instrumentation settings (async).
        /// </summary>
        public void SaveInstrumentedEmailSettingsAsync( InstrumentedEmailSettingsDto configuration )
        {
            // Create a new instrumentation client to handle this setting.
            var instrumentation = CreateInstrumentationServiceClient();

            // Create a request with the setting name and value.
            var requestBody = new SaveInstrumentedEmailSettingsRequestBody( configuration );
            var request = new SaveInstrumentedEmailSettingsRequest( requestBody );

            // When completed, update this instance.
            instrumentation.SaveInstrumentedEmailSettingsCompleted += ( sender, e ) =>
            {
                var result = e.Result;
                Contract.Assume( result != null );
                Contract.Assume( result.Body.SaveInstrumentedEmailSettingsResult );

                // Save the settings into the client instance for properties that
                // require client side code when reacting to instrumentation.
                if( configuration != null )
                {
                    clientEmailSettings = configuration;
                }
                else
                {
                    clientEmailSettings = new InstrumentedEmailSettingsDto();
                }

                // Raise the event indicating that the save is completed.
                this.OnSaveInstrumentedEmailSettingsCompleted( e );
            };

            // Initiate the asynchronous operation to configure the value.
            instrumentation.SaveInstrumentedEmailSettingsAsync( request );
        }

       #endregion

So the actual use of the above with in test:

        #region Tests - Alternative Flows, A1.X

        /// <summary>
        /// A1.1 Handle Request to E-mail Log File to Technical Support
        /// </summary>
        [TestMethod]
        [Tag( "Level 3" )]
        [Tag( "A1.1" )]
        [Asynchronous]
        [Timeout( OneMinuteTestTimeout )]
        public void A1_1_RequestToSendEmail()
        {
            // TEST PLAN
            // 1 Configure Instrumentation Error Report E-mail Settings with the
            // following property values, as described in the Configure
            // Instrumentation Settings for Testing (L2W.UC15) use case:
            //        E-mail Address = “test@testcompany.com”
            //        E-mail Disabled = Yes
            //        Diagnostic Notification Enabled = True
            this.EnqueueResetAllInstrumentation();
            InstrumentedEmailDiagnosticsInformation emailInformation = null;
            bool mainViewModelIsBusy = false;
            this.EnqueueSaveInstrumentedEmailSettings( new InstrumentedEmailSettingsDto
            {
                EmailDisabled = true,
                EmailAddress = "test@testcompany.com",
                DiagnosticNotificationCallback = ( callbackInfo ) =>
                    {
                        mainViewModelIsBusy = this.MainViewModel.IsBusy;
                        emailInformation = callbackInfo;
                    }
            } );

Coordinator
Apr 5, 2011 at 4:27 PM

Where are your services trying to talk to? What's in your ServiceReferences.clientconfig?

Also when you compile your test project - there is a file generated TestPage.html - Can your code run from there? If not, try to get that running, when you can get that to work - you will most likely get it to work with StatLight.

Apr 5, 2011 at 5:23 PM

ServiceReferences.clientconfig:

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_ITestInstrumentationWebService"
                         maxBufferSize="2147483647"
                         maxReceivedMessageSize="2147483647">
                    <security mode="TransportCredentialOnly" />
                </binding>
                <binding name="BasicHttpBinding_IApplicationPresentationService"
                         maxBufferSize="2147483647"
                         maxReceivedMessageSize="2147483647">
                    <security mode="TransportCredentialOnly" />
                </binding>
                <binding name="ApplicationPresentationWebServiceSoap"
                         maxBufferSize="2147483647"
                         maxReceivedMessageSize="2147483647">
                    <security mode="None" />
                </binding>
                <binding name="TestInstrumentationWebServiceSoap"
                         maxBufferSize="2147483647"
                         maxReceivedMessageSize="2147483647">
                    <security mode="None" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:2793/PresentationServices/ApplicationPresentationWebService.asmx"
                      binding="basicHttpBinding"
                      bindingConfiguration="ApplicationPresentationWebServiceSoap"
                      contract="ApplicationPresentationWebServices.ApplicationPresentationWebServiceSoap"
                      name="ApplicationPresentationWebServiceSoap" />
            <endpoint address="http://localhost:2793/InstrumentationServices/TestInstrumentationWebService.asmx"
                      binding="basicHttpBinding"
                      bindingConfiguration="TestInstrumentationWebServiceSoap"
                      contract="TestInstrumentationWebServices.TestInstrumentationWebServiceSoap"
                      name="TestInstrumentationWebServiceSoap" />
        </client>
    </system.serviceModel>
</configuration>

We have an AutomatedTest.aspx which is an expanded TestPage.html (the default TestPage.html does have issues) however our modified one works correctly.  We also have a Default.aspx that launches the application successfully.  Both of these aspx files are in the .Web branch

AutomatedTest.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AutomatedTests.aspx.cs" Inherits="Bsi.Build2Win.Web.AutomatedTests" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Automated Silverlight Tests</title>
    <style type="text/css">
    html, body {
        height: 100%;
        overflow: auto;
    }
    body {
        padding: 0;
        margin: 0;
    }
    #silverlightControlHost {
        height: 100%;
        text-align:center;
    }
    </style>
    <script type="text/javascript" src="AutomatedTests.Silverlight.js"></script>
    <script type="text/javascript" src="">
        function onSilverlightError(sender, args)
        {
            var appSource = "";
            if (sender != null && sender != 0)
            {
                appSource = sender.getHost().Source;
            }

            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;

            if (errorType == "ImageError" || errorType == "MediaError")
            {
                return;
            }

            var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

            errMsg += "Code: " + iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";

            if (errorType == "ParserError")
            {
                errMsg += "File: " + args.xamlFile + "     \n";
                errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError")
            {
                if (args.lineNumber != 0)
                {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " + args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }

            throw new Error(errMsg);
        }
    </script>
</head>
<body>
    <form id="form2" runat="server" style="height:100%">
        <div id="silverlightControlHost">
            <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
                <param name="source" value="ClientBin/Bsi.Build2Win.Silverlight.Tests.xap"/>
                <param name="onError" value="onSilverlightError" />
                <param name="background" value="white" />
                <param name="minRuntimeVersion" value="4.0.50401.0" />
                <param name="autoUpgrade" value="true" />
                <param ID="InitParams" runat="server" name="Initparams" value="" />
                <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration:none">
                    <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
                </a>
            </object>
            <iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
        </div>
    </form>
</body>
</html>

Coordinator
Apr 5, 2011 at 7:57 PM

Everything from the looks of it is looking good. I've had trouble in StatLight returning the silverlight client access policy file, and had to roll-back to using supported flash version. Here is what StatLight's cross domain file looks like - https://github.com/staxmanade/StatLight/blob/master/src/StatLight.Core/Resources/CrossDomain.xml

What do your service's cross domain policy file look like?

Apr 6, 2011 at 12:32 PM

It looks just as you have above.  Maybe I am not getting it placed in the correct location locally?  Where should this reside? or is it enough that it is built with the src?

I keep hoping I am just missing something trivial.  I am fairly new to Silverlight/VS :)

Coordinator
Apr 6, 2011 at 1:38 PM

Since you have a webservice here http://localhost:2793/PresentationServices/ApplicationPresentationWebService.asmx

Can you access the CrossDomain file at http://localhost:2793/CrossDomain.xml

Apr 6, 2011 at 5:22 PM

Ok, So I do believe have it in the correct place.

ASP.NET Development Server:

Root URL: http://localhost:2793/

Port: 2793

Virtual Path: /

Physical Path: C:\LOGISTICS\Application\Bid2Win.FieldTracking.Web\

I have the xml in the Physical Path, but also tried the virtual path as well with no difference results.

I guess what is bothering me is the http path in the error:

System.ServiceModel.CommunicationException: An error occurred while trying to make a request to URI
'http://instrumentationservices/TestInstrumentationWebService.asmx'.

If I access http://localhost:2793/instrumentationservices/TestInstrumentationWebService.asmx the page is server up.  Without the localhost identifier it fails.

Coordinator
Apr 6, 2011 at 6:09 PM

Yes, you have to have the server(localhost) and port(2793) specified in the full path.

Apr 6, 2011 at 6:16 PM
Edited Apr 6, 2011 at 6:17 PM

So if that is the crux of the problem how do I get the path set correctly?  I had thought the ServiceReferences.ClientConfig was used for this.  Is there some place else this needs to be defined?

Coordinator
Apr 6, 2011 at 6:46 PM

How is CreateInstrumentationServiceClient() implemented?

FYI: we could probably diagnose this faster, if you could create a sample set of projects and sent over a zip up example.

Apr 6, 2011 at 7:00 PM

It is implemented as follows:

 

        private static TestInstrumentationWebServiceSoapClient CreateInstrumentationServiceClient()
        {
            Contract.Ensures( Contract.Result<TestInstrumentationWebServiceSoapClient>() != null );

            var service = new TestInstrumentationWebServiceSoapClient();
            var app = Application.Current;

            // Get the full path to the xap file.
            // Example: http://localhost:2793/ClientBin/Bsi.Build2Win.Silverlight.xap
            Contract.Assume( ( app != null ) && ( app.Host != null ) && ( app.Host.Source != null ) );
            var xapUri = app.Host.Source.AbsoluteUri;

            // Chop off the xap file name, leaving the path to the ClientBin directory
            // Example: http://localhost:2793/ClientBin
            var xapUriLastSlashIndex = xapUri.LastIndexOf( '/' );
            Contract.Assume( xapUriLastSlashIndex >= 0 );
            var clientBinUri = xapUri.Substring( 0, xapUriLastSlashIndex );

            // Chop off everything but the root portion of the URI.
            // Example: http://localhost:2793
            var clientBinUriLastSlashIndex = clientBinUri.LastIndexOf( '/' );
            Contract.Assume( clientBinUriLastSlashIndex >= 0 );
            var rootUri = clientBinUri.Substring( 0, clientBinUriLastSlashIndex );

            // Get the configured service.  We make an assumption for this -- it assumes the root path for BUILD2WIN is "/"
            // For typical implementations, this will not be the case; it will be, E.G, "http://localhost/BUILD2WIN/"
            Contract.Assume( ( service.Endpoint != null ) && ( service.Endpoint.Address != null ) && ( service.Endpoint.Address.Uri != null ) );
            var configurePath = service.Endpoint.Address.Uri.AbsolutePath;

            // Append relative path loaded from configuration, and append it to the web site root.
            service.Endpoint.Address = new System.ServiceModel.EndpointAddress(
                rootUri
                + configurePath );

            return service;
        }

the service value does contain the localhost:Port information.

Agreed on the sample project aspect, It would be untwining things to a small project which I have not had a chance to do.  I might be able to see about this over the weekend if we have not figured something out by then.

Thanks for all your help :)

Apr 7, 2011 at 1:49 PM

So I was able to make some progress, within the CreateInstrumentationServiceClient, when we get the full path to the URI it was returning

app.Host.Source.AbsoluteUri = "http://localhost:8887/StatLight.Client.Harness.xap"

We added the following HACK to get the URI correct:

            // Chop off everything but the root portion of the URI.
            // Example: http://localhost:2793
            string rootUri = clientBinUri;
            if( rootUri.EndsWith( "/ClientBin", StringComparison.InvariantCultureIgnoreCase ) )
            {
                // HACK: When running under statlight, ClientBin will already be removed.  This logic will not be executed under that scenario.
                var clientBinUriLastSlashIndex = clientBinUri.LastIndexOf( '/' );
                Contract.Assume( clientBinUriLastSlashIndex >= 0 );
                rootUri = clientBinUri.Substring( 0, clientBinUriLastSlashIndex );
            }

So now when I run the error is:

*****************************************
An unknown request was made to the StatLight's web server. You may want to check your test project for what generated the following request.
********** Request Information **********
Url : http://localhost:8887/InstrumentationServices/TestInstrumentationWebService.asmx
HttpMethod : POST
PostData : <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><ResetAllSettings xmlns="http://bid2win.com/BUILD2WIN" /></s:Body></s:Envelope>
*****************************************

Coordinator
Apr 7, 2011 at 7:03 PM

yes, StatLight is the "host" application and it is bing served up by the StatLight web server. So app.Host.Source.{anything} will always be StatLight related.

Did you try hard-coding the rootUri to http://localhost:{externalServicePort} and see if it fixes your problem? I have some ideas of how you can re-configure things if that does work.

Apr 7, 2011 at 8:49 PM

That appears to have corrected the URI issue and I have gotten much farther now.  I am getting some timeout errors as well as an error stating remote server not found.  Those are somewhat odd as I am running locally, nothing is really remote, but I will debug those some more first.

But it did just complete with:

--- Completed Test Run at: 4/7/2011 4:44:41 PM. Total Run Time: 00:48:03.9360000

Test run results: Total 307, Successful 293, Failed 14,

YEAH!  Will just need to figure out the remaining 14.

So if you have any recommendations on re-configuring please let me know.

Another quick question - do you have any examples for using the XML Report XSD?

Coordinator
Apr 8, 2011 at 3:38 AM

Congrats on getting it working.

Regarding something to try. I'm not giving this as the "best advice for the job", but it's an approach you can try.

For something like this I might use a static Func<string> for example and configure it to return the production connection.

 

public class ServiceConnectionSettings
{
    public static Func<string> GetCurrentServiceRootUrl = ()=> SomeFunctionThatHasYourProductionConfig;

}

 

Next in your test framework you can leverage the (if you're using MSTest) the AssemblyInitialize attribute to place some code to override your production connection.

 

[TestClass]
public class GlobalInitialization
{
    [AssemblyInitialize]
    public void Setup()
    {
         ServiceConnectionSettings.GetCurrentServiceRootUrl = ()=>"http://localhost:12345/";
     }
}

Hope this helps.

Happy Testing.