none
Why my WCF service work on VS development server and not on IIS 7.0?

    Question

  •  Maybe is a problem of endpoint, but i can't to find a solution (IIS is already confiured for host a wcf)

      <system.serviceModel>
            <behaviors>
        <serviceBehaviors>
          <behavior name="ServiceBehavior">
            <serviceMetadata httpGetEnabled="true" />
            <serviceDebug includeExceptionDetailInFaults="false" />
          </behavior>
        </serviceBehaviors>
      </behaviors>
        <services>
        <service behaviorConfiguration="ServiceBehavior" name="Service">
          <endpoint address="" binding="basicHttpBinding" contract="IService" />
          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
      </services>
        </system.serviceModel>

    thanks..

    Tuesday, September 02, 2008 8:02 AM

Answers

  •  For everyone, i have finally solved the problem.

    When i'll have few minutes, i'll write the solution.

     Thanks so much to everybody.

    Friday, September 05, 2008 3:00 PM

All replies

  • Hi,

    You Can specify Your end Point address over here which is empty Right know....

    Are you having clientAccess Policy at its Root.

    Can you Let me know what error are you getting..

    Tuesday, September 02, 2008 8:11 AM
  •  You talking about that?

            <system.web>
                <securityPolicy>
                    <trustLevel name="Full" policyFile="internal"/>
                    <trustLevel name="High" policyFile="web_hightrust.config"/>
                    <trustLevel name="Medium" policyFile="web_mediumtrust.config"/>
                    <trustLevel name="Low" policyFile="web_lowtrust.config"/>
                    <trustLevel name="Minimal" policyFile="web_minimaltrust.config"/>
                </securityPolicy>
                <trust level="High" originUrl=""/>
            </system.web>
     

    Tuesday, September 02, 2008 8:15 AM

  • You Can specify Your end Point address over here which is empty Right know....

     

    i have tryed to specify the address like that:

      </behaviors>
        <services>
        <service behaviorConfiguration="ServiceBehavior" name="Service">
          <endpoint address="http://192.168.0.2/" binding="basicHttpBinding" contract="IService" />
          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
      </services>
        </system.serviceModel>

    but not work 

    Tuesday, September 02, 2008 8:18 AM
  • Hi,

    I think it should work..

    You Can try by giving address like this.

    http://192.168.0.2/Services1.svc

    Tuesday, September 02, 2008 8:32 AM
  • Hi,

    I think it should work..

    You Can try by giving address like this.

    http://192.168.0.2/Services1.svc

     

    Not work unfortunately..

    Tuesday, September 02, 2008 8:37 AM
  •  

    This post may help:

    http://www.bluerosegames.com/SilverlightBrassTacks/post/Calling-WCF-on-the-local-server-from-Silverlight.aspx

     

    Hi, my application not make a 404 error, she run, but when i go to call the method for retrieve 

    SQLdatabase data through WCF, she return nothing.

    Tuesday, September 02, 2008 8:45 AM
  • What happens if you type the url for the WCF service into the browser? If that comes back with an error, then your problem is server side, and you can track down the problem by examining the error that is shown. If you get the service information page, then it's a client side issue and I'd recommend what I wrote about in that article. Your other possibility is a cross domain issue, but it sounds like you're trying to access a service on the same server that is serving up the page, and if so, then cross domain shouldn't enter into it.

    Tuesday, September 02, 2008 8:55 AM
  • This post may help:

    http://www.bluerosegames.com/SilverlightBrassTacks/post/Calling-WCF-on-the-local-server-from-Silverlight.aspx

     

     

    Nothing, i have modified also the servicereference.clientconfig endpoint address with 192.168.0.2, 192.168.0.2:80, with localhost

    and not work.

    I can't understand :° 

    Tuesday, September 02, 2008 8:57 AM
  • What happens if you type the url for the WCF service into the browser? If that comes back with an error, then your problem is server side, and you can track down the problem by examining the error that is shown. If you get the service information page, then it's a client side issue and I'd recommend what I wrote about in that article. Your other possibility is a cross domain issue, but it sounds like you're trying to access a service on the same server that is serving up the page, and if so, then cross domain shouldn't enter into it.

     

    Return the view of service:

     

    Tuesday, September 02, 2008 9:02 AM
  • Ok so it's a client side problem. What do you see if you run Fiddler? http://www.fiddlertool.com/fiddler/

     

    Tuesday, September 02, 2008 9:04 AM
  • Ok so it's a client side problem. What do you see if you run Fiddler? http://www.fiddlertool.com/fiddler/

     

     

     that:

     

    Tuesday, September 02, 2008 9:06 AM
  • I meant install and run Fiddler and see what's going back and forth between your client and server. You can then see if your Silverlight app is hitting the right address when you make the service request.

    Tuesday, September 02, 2008 9:10 AM
  •  LoL, sorry... now i try.

    Tuesday, September 02, 2008 9:12 AM
  • I meant install and run Fiddler and see what's going back and forth between your client and server. You can then see if your Silverlight app is hitting the right address when you make the service request.

     

    When i run fiddler i show this view:

     

    Tuesday, September 02, 2008 9:19 AM
  •  

    Tuesday, September 02, 2008 9:28 AM
  • Doesn't even look like it's loading your xap file...not sure why you're getting the 501 and 405 errors,but I don't think it's a Silverlight problem.

    Tuesday, September 02, 2008 9:51 AM
  •  Is an endpoint address problem, because, when i change the endpoint address the wcf in development server stop to work like in the IIS default configuration..I must to find the right endpoint address but i can't understand how, infact i try a lot of address but nothin of they work..

    I'm going crazy.

     

    Tuesday, September 02, 2008 9:58 AM
  •  Is an endpoint address problem, because, when i change the endpoint address the wcf in development server stop to work like in the IIS default configuration..I must to find the right endpoint address but i can't understand how, infact i try a lot of address but nothin of they work..


    You can do this to by-pass the URL reading from ServiceReference.ClientConfig. Set your URL in the code.  Change your WebSerivice Calling code to the following:

              var webService = new YourWebService.YourWebServiceClient() // This is the default constructor, url will be read from the clientconfig file.

              Uri address = new Uri(Application.Current.Host.Source, "../YourService.svc"); // this url is dynamically built, will work both in dev server and IIS

              var webService = new YourWebService.YourWebServiceClient("YourServiceEndPointName", address.AbsoluteUrl); // find your EndPointName in your ClientConfig, you can still use the Binding information set in that file, but not URL

    This way you do not mess up with the ClientConfig from develop to deploy,  and you do not have any cross-domain issue so you do not even need clientaccesspolicy.xml file.

     


    Tuesday, September 02, 2008 10:34 AM
  •           var webService = new YourWebService.YourWebServiceClient() // This is the default constructor, url will be read from the clientconfig file.

              Uri address = new Uri(Application.Current.Host.Source, "../YourService.svc"); // this url is dynamically built, will work both in dev server and IIS

              var webService = new YourWebService.YourWebServiceClient("YourServiceEndPointName", address.AbsoluteUrl); // find your EndPointName in

     hi sladpter

    On what file i can read this information?...i not see that variables in any files..


    Tuesday, September 02, 2008 12:50 PM
  •  Just replace the code where you create your WebSerivceClient in your Service Calling code(should be in your UserContro's code behind):

    Replace this line of code with the new code:

     YourWebService.YourWebServiceClient service = new YourWebService.YourWebServiceClient();  // This is the default constructor, if you use the default constructor, url will be read from the clientconfig file.

    Uri address = new Uri(Application.Current.Host.Source, "../YourService.svc"); // this url is dynamically built, will work both in dev server and IIS

     YourWebService.YourWebServiceClient webService = new YourWebService.YourWebServiceClient("YourServiceEndPointName", address.AbsoluteUrl); 

     

     


    Tuesday, September 02, 2008 1:07 PM
  • Edit..Ok i understand.

     

     

    Tuesday, September 02, 2008 1:58 PM
  •  Just replace the code where you create your WebSerivceClient in your Service Calling code(should be in your UserContro's code behind):

    Replace this line of code with the new code:

     YourWebService.YourWebServiceClient service = new YourWebService.YourWebServiceClient();  // This is the default constructor, if you use the default constructor, url will be read from the clientconfig file.

    Uri address = new Uri(Application.Current.Host.Source, "../YourService.svc"); // this url is dynamically built, will work both in dev server and IIS

     YourWebService.YourWebServiceClient webService = new YourWebService.YourWebServiceClient("YourServiceEndPointName", address.AbsoluteUrl); 

     

     

    This method continue to not work under iis. I have modified the code like that:      

      static Uri address= new Uri(Application.Current.Host.Source, "../Service.svc");
           ServiceReference.ServiceClient client = new ServiceReference.ServiceClient("BasicHttpBinding_IService", address.AbsoluteUri);
     
     

     

    Tuesday, September 02, 2008 3:45 PM
  •  Have you tried to hit your Service in a browser by typing in the Service URL something like http://localhost/YourWebSite/Service.svc?

    Can you hit your service this way?

     

    Tuesday, September 02, 2008 3:48 PM
  • I don't think it's even getting into your Silverlight app, can you comment out all service calls and see if it comes up? Also can you try the html test page instead of the aspx test page?

    Tuesday, September 02, 2008 3:58 PM
  •  Have you tried to hit your Service in a browser by typing in the Service URL something like http://localhost/YourWebSite/Service.svc?

    Can you hit your service this way?

     

     

    Yes (the result is in italian, because i'm italian):

    Servizio Service
    
    È stato creato un servizio.
    
    Per testare il servizio, è necessario creare un client e utilizzarlo per chiamare il servizio. A tale scopo utilizzare lo strumento svcutil.exe dalla riga di comando con la sintassi seguente:
    
    svcutil.exe http://pc-luca:81/wcf/Service.svc?wsdl
    
    Verrà generato un file di configurazione e un file di codice contenente la classe client. Aggiungere i due file all'applicazione client e utilizzare la classe client generata per chiamare il servizio. Ad esempio:
    
    C#
    
    class Test
    {
        static void Main()
        {
            ServiceClient client = new ServiceClient();
    
            // Utilizzare la variabile 'client' per chiamare le operazioni nel servizio.
    
            // Chiudere sempre il client.
            client.Close();
        }
    }
    
    
    Visual Basic
    
    Class Test
        Shared Sub Main()
            Dim client As ServiceClient = New ServiceClient()
            ' Utilizzare la variabile 'client' per chiamare le operazioni nel servizio.
    
            ' Chiudere sempre il client.
            client.Close()
        End Sub
    End Class
     
      
    Tuesday, September 02, 2008 4:09 PM
  • I don't think it's even getting into your Silverlight app, can you comment out all service calls and see if it comes up? Also can you try the html test page instead of the aspx test page?

     

    Also in the html page not work unfortunately..

    Tuesday, September 02, 2008 4:11 PM
  •  Good Morning everyone, the problem persist : D

     Wanna find the solution together?

     

    Thank you.

    Wednesday, September 03, 2008 6:19 AM
  • Did you do what I asked and try commenting out all of the WCF service calls and see if it loads? I really don't think it's a WCF problem you're having.

    Wednesday, September 03, 2008 6:45 AM
  • Hi,

    so the service is up and running at http://pc-luca:81/wcf/Service.svc?wsdl, right?

    Now:

    - create a new Silverlight project;

    - add a service reference to http://pc-luca:81/wcf/Service.svc?wsdl, name it ServiceReference1;

    - add to Page.xaml the code:

    <Button x:Name="btnTest" Content="Test" Click="btnTest_Click"/>

    - add to Page.xaml.cs the event-handler for the button:

    private void btnTest_Click(object sender, RoutedEventArgs e)

    {

    ServiceReference1.YourServiceClient ser= new ServiceReference1.YourServiceClient();

    ser.YourMethodCompleted += (se, ev) =>

    {

    if (ev.Error == null)

    {

    btnTest.Content = ev.result.ToString();

    }

    else

    {

    btnTest.Content = ev.Error.Message;

    }

    };

    ser.YourMethodAsync(); 

    }

    - try to run the Silverlight Web project

     

    Wednesday, September 03, 2008 6:45 AM
  • Hi,

    so the service is up and running at http://pc-luca:81/wcf/Service.svc?wsdl, right?

    Now:

    - create a new Silverlight project;

    - add a service reference to http://pc-luca:81/wcf/Service.svc?wsdl, name it ServiceReference1;

    - add to Page.xaml the code:

    <Button x:Name="btnTest" Content="Test" Click="btnTest_Click"/>

    - add to Page.xaml.cs the event-handler for the button:

    private void btnTest_Click(object sender, RoutedEventArgs e)

    {

    ServiceReference1.YourServiceClient ser= new ServiceReference1.YourServiceClient();

    ser.YourMethodCompleted += (se, ev) =>

    {

    if (ev.Error == null)

    {

    btnTest.Content = ev.result.ToString();

    }

    else

    {

    btnTest.Content = ev.Error.Message;

    }

    };

    ser.YourMethodAsync(); 

    }

    - try to run the Silverlight Web project

     

     

    Hi,

    so the service is up and running at http://pc-luca:81/wcf/Service.svc?wsdl, right?

    Now:

    - create a new Silverlight project;

    - add a service reference to http://pc-luca:81/wcf/Service.svc?wsdl, name it ServiceReference1;

    - add to Page.xaml the code:

    <Button x:Name="btnTest" Content="Test" Click="btnTest_Click"/>

    - add to Page.xaml.cs the event-handler for the button:

    private void btnTest_Click(object sender, RoutedEventArgs e)

    {

    ServiceReference1.YourServiceClient ser= new ServiceReference1.YourServiceClient();

    ser.YourMethodCompleted += (se, ev) =>

    {

    if (ev.Error == null)

    {

    btnTest.Content = ev.result.ToString();

    }

    else

    {

    btnTest.Content = ev.Error.Message;

    }

    };

    ser.YourMethodAsync(); 

    }

    - try to run the Silverlight Web project

     



    Ciao.

    Già ho fatto tutto, é tutto impostato. L'applicazione funziona sul server di visual studio, ma non su IIS 7,

    per un problema di endpoint che non riesco a risolvere.

    Quando modifico l'endpoint dal servicereference.clientconfig, l'applicazione che prima girava

    sul server visual studio si comporta nello stesso modo di quella che si trova sulle pagine caricate da server iis,

    a dimostrazione che il problema sta li, per questo lo sto dicendo.

    L'applicazione deve ritornare dei valori contenuti in un database sql dentro un textblock.

    Con il metodo che mi ha suggerito sladapter prima, qualcosa é cambiato, perché al click dell'oggetto

    il server iis inizia a caricare qualcosa, cosa che prima non faceva, però i risultati non me li da lo stesso.


    Wednesday, September 03, 2008 6:55 AM
  • Strano,

    ho diversi servizi WCF che usano LINQ to SQL pubblicati su IIS7 che funzionano senza problemi richiamati da Silverlight.

    Ecco la configurazione che uso:

    web.config lato server:

    <endpoint address=""

    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"

    contract="Service.IService" name="BasicHttpBinding_IService" />

    ServiceReferences.ClientConfig:

    <endpoint address=http://localhost/MyService/Service.svc

    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"

    contract="MyService.IService"

    name="BasicHttpBinding_IService" />

     

    Wednesday, September 03, 2008 7:23 AM
  • Strano,

    ho diversi servizi WCF che usano LINQ to SQL pubblicati su IIS7 che funzionano senza problemi richiamati da Silverlight.

    Ecco la configurazione che uso:

    web.config lato server:

    <endpoint address=""

    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"

    contract="Service.IService" name="BasicHttpBinding_IService" />

    ServiceReferences.ClientConfig:

    <endpoint address=http://localhost/MyService/Service.svc

    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"

    contract="MyService.IService"

    name="BasicHttpBinding_IService" />

     

     

     

    Questo invece é il mio web.config allo stato attuale:

     

      <system.serviceModel>
    		<behaviors>
        <serviceBehaviors>
          <behavior name="ServiceBehavior">
            <serviceMetadata httpGetEnabled="true" />
            <serviceDebug includeExceptionDetailInFaults="false" />
          </behavior>
        </serviceBehaviors>
      </behaviors>
        <services>
        <service behaviorConfiguration="ServiceBehavior" name="Service">
          <endpoint address="" binding="basicHttpBinding" contract="IService" />
          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
      </services>
    	</system.serviceModel>
    

      

    Mentre quest'altro é il clientcongif:

     

    <configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_IService" maxBufferSize="65536"
                        maxReceivedMessageSize="65536">
                        <security mode="None" />
                    </binding>
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost/wcf/Service.svc"
                    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
                    contract="SilverlightApplication6.LucaMarcelliNameSpaceReference.IService"
                    name="BasicHttpBinding_IService" />
            </client>
        </system.serviceModel>
    </configuration>

      

     Non so, si nota qualcosa di  strano, di sbagliato, non ne ho idea.

    Wednesday, September 03, 2008 8:07 AM
  • Le configurazioni sono corrette, puoi provare ad aumentare il valore dei timeout e dei buffer nella sezione "bindings" del web.config relativo al servizio:

    <bindings>

    <basicHttpBinding>

    <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"

    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

    allowCookies="false" bypassProxyOnLocal="false"   hostNameComparisonMode="StrongWildcard"

    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"

    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

    useDefaultWebProxy="true">

    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"

    maxBytesPerRead="4096" maxNameTableCharCount="16384" />

    <security mode="None">

    <transport clientCredentialType="None" proxyCredentialType="None"

    realm="" />

    <message clientCredentialType="UserName" algorithmSuite="Default" />

    </security>

    </binding>

    </basicHttpBinding>

    </bindings>

    Wednesday, September 03, 2008 8:17 AM
  • Le configurazioni sono corrette, puoi provare ad aumentare il valore dei timeout e dei buffer nella sezione "bindings" del web.config relativo al servizio:

    <bindings>

    <basicHttpBinding>

    <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"

    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

    allowCookies="false" bypassProxyOnLocal="false"   hostNameComparisonMode="StrongWildcard"

    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"

    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

    useDefaultWebProxy="true">

    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"

    maxBytesPerRead="4096" maxNameTableCharCount="16384" />

    <security mode="None">

    <transport clientCredentialType="None" proxyCredentialType="None"

    realm="" />

    <message clientCredentialType="UserName" algorithmSuite="Default" />

    </security>

    </binding>

    </basicHttpBinding>

    </bindings>

     

    Nulla, ho modificato il web.config esattamente come il tuo ma non ha cambiato niente:

     

    1      <system.serviceModel>
    2        <bindings>
    3          <basicHttpBinding>
    4            <binding name="BasicHttpBinding_IService" 
    5                     closeTimeout="00:01:00"
    6                     openTimeout="00:01:00" 
    7                     receiveTimeout="00:10:00" 
    8                     sendTimeout="00:01:00"
    9                     allowCookies="false" 
    10                    bypassProxyOnLocal="false"   
    11                    maxBufferSize="65536" 
    12                    maxBufferPoolSize="524288" 
    13                    maxReceivedMessageSize="65536"
    14                    messageEncoding="Text" 
    15                    textEncoding="utf-8" 
    16                    transferMode="Buffered"
    17                    useDefaultWebProxy="true">
    18   
    19           <readerQuotas maxDepth="32" 
    20                         maxStringContentLength="8192" 
    21                         maxArrayLength="16384"
    22                         maxBytesPerRead="4096" 
    23                         maxNameTableCharCount="16384" />          
    24             <security mode="None" />
    25           </binding>
    26         </basicHttpBinding>
    27       </bindings>
    28       <behaviors>
    29       <serviceBehaviors>
    30         <behavior name="ServiceBehavior">
    31           <serviceMetadata httpGetEnabled="true" />
    32           <serviceDebug includeExceptionDetailInFaults="false" />
    33         </behavior>
    34       </serviceBehaviors>
    35     </behaviors>
    36       <services>
    37       <service behaviorConfiguration="ServiceBehavior" name="Service">
    38         <endpoint address="" 
    39                   bindingConfiguration="BasicHttpBinding_IService" 
    40                   binding="basicHttpBinding" 
    41                   contract="IService" 
    42                   name="BasicHttpBinding_IService" />
    43         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    44       </service>
    45     </services>
    46   	</system.serviceModel>
    47   
    
      
    Wednesday, September 03, 2008 8:30 AM
  •  Potrebbe entrarci qualcosa Sql Server?..C'é quella installata da visual studio nel mio pc

    Wednesday, September 03, 2008 8:46 AM
  • A questo punto conviene fare un po' di debug nel servizio.

    Prova a commentare tutto il codice LINQ e ritornare solo una semplice stringa, in modo da verificare che il servizio e l'applicativo SL funzionino correttamente su IIS (in questo modo escludiamo LINQ to SQL come causa).

    Wednesday, September 03, 2008 8:53 AM
  • A questo punto conviene fare un po' di debug nel servizio.

    Prova a commentare tutto il codice LINQ e ritornare solo una semplice stringa, in modo da verificare che il servizio e l'applicativo SL funzionino correttamente su IIS (in questo modo escludiamo LINQ to SQL come causa).

     

    Adesso posto il progetto completamente, in tutti i passaggi che ho attuato, e i metodi, perché mi sembra davvero strano che non funzioni.

    Wednesday, September 03, 2008 9:02 AM
  • A questo punto conviene fare un po' di debug nel servizio.

    Prova a commentare tutto il codice LINQ e ritornare solo una semplice stringa, in modo da verificare che il servizio e l'applicativo SL funzionino correttamente su IIS (in questo modo escludiamo LINQ to SQL come causa).

     

    Adesso posto il progetto completamente, in tutti i passaggi che ho attuato, e i metodi, perché mi sembra davvero strano che non funzioni.

     

    This image rappresent the method that work on developer server and not on IIS 7.0:


     

     

    Wednesday, September 03, 2008 9:41 AM
  •  Web_Horse,

    How do you connect to Database? Are you using Window authentication or SQL server authentication? If you are using Window authentication, it might be the problem with Database connection, not with Service connection. Because when you running under Dev Server, the LoginUser is the current window user, so it can connect to database using Window authentication, But when you running under IIS, the LoginUser is the IUserXXX,  which may not have access right to your database. So it's best to use SQL server authentication in your connection string in Web application.

    Any exception thrown in your Service code could also result 404 error if you did not catch the error in your Service code. One way to make sure the real error is passed back to Silverlight is to catch the exception before your Service returns. Use a Out paramerter to pass that error message back to Silverlight:

    [OperationContract]
            public YourReturnObject  YourServiceFunction(someParam,  out string ServiceError)
            {
                try
                {
                    ServiceError = null;
                    // your code here
                }
                catch (Exception err)
                {
                    ServiceError = err.Message;
                }
                return YourReturnObject;
            }          

    In YourServiceFunctionCompleted event handler in Silverlight code:

     void YourService_YourFunctionCompleted(object sender,  CompletedEventArgs e)
            {

    if (e.Error == null && e.ServiceError == null)
                {
                    //Use e.Result
                }
                else if (e.Error != null)
                {
                    HtmlPage.Window.Alert(e.Error.Message);
                }
                else if (e.ServiceError != null)
                     HtmlPage.Window.Alert(e.ServiceError);  // Now you know what real error is

     }

    Wednesday, September 03, 2008 11:11 AM
  •  Web_Horse,

    How do you connect to Database? Are you using Window authentication or SQL server authentication? If you are using Window authentication, it might be the problem with Database connection, not with Service connection. Because when you running under Dev Server, the LoginUser is the current window user, so it can connect to database using Window authentication, But when you running under IIS, the LoginUser is the IUserXXX,  which may not have access right to your database. So it's best to use SQL server authentication in your connection string in Web application.

    Any exception thrown in your Service code could also result 404 error if you did not catch the error in your Service code. One way to make sure the real error is passed back to Silverlight is to catch the exception before your Service returns. Use a Out paramerter to pass that error message back to Silverlight:

    [OperationContract]
            public YourReturnObject  YourServiceFunction(someParam,  out string ServiceError)
            {
                try
                {
                    ServiceError = null;
                    // your code here
                }
                catch (Exception err)
                {
                    ServiceError = err.Message;
                }
                return YourReturnObject;
            }          

    In YourServiceFunctionCompleted event handler in Silverlight code:

     void YourService_YourFunctionCompleted(object sender,  CompletedEventArgs e)
            {

    if (e.Error == null && e.ServiceError == null)
                {
                    //Use e.Result
                }
                else if (e.Error != null)
                {
                    HtmlPage.Window.Alert(e.Error.Message);
                }
                else if (e.ServiceError != null)
                     HtmlPage.Window.Alert(e.ServiceError);  // Now you know what real error is

     }

     

    I think use windows authentication:

     

    		<compilation debug="true">
    <assemblies>
    <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /></assemblies>
    </compilation>
    <!--
    La sezione <authentication> consente di configurare
    la modalità di autenticazione della sicurezza utilizzata da
    ASP.NET per identificare un utente in ingresso.
    -->

    <authentication mode="Windows" />
    <!--
    La sezione <customErrors> consente di configurare
    l'operazione da eseguire in caso di errore non gestito
    durante l'esecuzione di una richiesta. In particolare,
    consente agli sviluppatori di configurare le pagine di errore HTML
    in modo che vengano visualizzate al posto dell'analisi dello stack dell'errore.

    <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
    <error statusCode="403" redirect="NoAccess.htm" />
    <error statusCode="404" redirect="FileNotFound.htm" />
    </customErrors>
    -->

    <pages>

     

    How to set the right authentication mode?

     This is my connectionstring:

     

    		</sectionGroup>
    	</configSections>
    	<appSettings />
    
    	<connectionStrings>
            <remove name="LocalSqlServer" />
      <add name="database1ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database1.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
     </connectionStrings>
    
    	<system.web>
    		<!-- 
                Impostare compilation debug="true" per inserire i 
                simboli di debug nella pagina compilata. Poiché tale
                operazione ha effetto sulle prestazioni, impostare questo valore su true 
                solo durante lo sviluppo.
            -->
    		<compilation debug="true">
    			<assemblies>
    
      

     

    Wednesday, September 03, 2008 11:44 AM
  • Change your connection string:

    <add name="database1ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database1.mdf; Integrated Security=False; User ID=sa; Password=YoursaPassword; User Instance=True" providerName="System.Data.SqlClient"
    Every SQLserver has a "sa" (admin of the SQL server) login. You need to find out password or set the password for that user.
    Or you can add a User as your App User in your SQL server. Set up the login and password. Put that User ID and Password in your connection string,  
    Test you connection string in VS Server Explorer first. 
    Make sure to put try/catch code in your Service code so you can catch all the Server side error (also to confirm this is the cause of your problem). 

     
    Wednesday, September 03, 2008 11:58 AM
  •  The try/cacth method generate an error when i go to update the service reference..

    this is my contract: 

    [ServiceContract]
    public interface IService
    {
    [OperationContract]
    List OttieniContenuto(string OggettoRichiesto);

    }
     
    this my class: 
    public class Service : IService
    {
    #region IService Membri di

    public List OttieniContenuto(string OggettoRichiesto)
    {
    DataClassesDataContext database = new DataClassesDataContext();
    var ContenutiOttenuti = from Content in database.Content
    where Content.categoria.StartsWith(OggettoRichiesto)
    select Content;
    return ContenutiOttenuti.ToList();
    }

    #endregion
     
    THe "sa" authentication was not dangerous? 
     
      
     
    Wednesday, September 03, 2008 12:15 PM
  • 1)Your Service just returns List not List<YourObject>?

    [ServiceContract]
    public interface IService
    {
    [OperationContract]
    List OttieniContenuto(string OggettoRichiesto);
    //should be
    List<SomeObject> OttieniContenuto(string OggettoRichiesto, out string ServiceError);
    }
    2) Remove the service Reference first, then re-add it.
    3) "sa" is the SQL server admin login. You do not have to use it.  As I said, you can add a App User and give it certain right. Use the App User to login. 
    For your testing purpose, you can use "sa" first to make sure it was the Database connection issue. 
     
     
     
    Wednesday, September 03, 2008 12:28 PM
  • 1)Your Service just returns List not List<YourObject>?

    [ServiceContract]
    public interface IService
    {
    [OperationContract]
    List OttieniContenuto(string OggettoRichiesto);
    //should be
    List<SomeObject> OttieniContenuto(string OggettoRichiesto, out string ServiceError);
    }
    2) Remove the service Reference first, then re-add it.
    3) "sa" is the SQL server admin login. You do not have to use it.  As I said, you can add a App User and give it certain right. Use the App User to login. 
    For your testing purpose, you can use "sa" first to make sure it was the Database connection issue. 
     
     
    
    
    This is the error when i add the new service with try catch modify:

     
    Wednesday, September 03, 2008 12:50 PM
  • I don't know what the message is saying. But It's not because of try/catch, it's because you added that out parameter.

    I know this is very common way to pass the error back to Silverlight. I have it working without any problem, and I know a lot of people have it working. If you still can not make it working, remove that out parameter for now (you can try it later). Just log your error in the event log or a file log so at least you have a way to see what is going on if you have error in your Service when you running the web under IIS.

    Just change your connection string to do the test. 

     

     

    Wednesday, September 03, 2008 1:05 PM
  • I don't know what the message is saying. But It's not because of try/catch, it's because you added that out parameter.

    I know this is very common way to pass the error back to Silverlight. I have it working without any problem, and I know a lot of people have it working. If you still can not make it working, remove that out parameter for now (you can try it later). Just log your error in the event log or a file log so at least you have a way to see what is going on if you have error in your Service when you running the web under IIS.

    Just change your connection string to do the test. 

     

     

    Hi sladapter,

    i'm manage to resolve the service reference compilation error, and i find the problem in IIS in the alert with your method:

    he say it (in italian...how do i do for change the language error in english?)

     

    Thursday, September 04, 2008 8:18 AM
  •  This is with more information (Exception.Source and Exception.InnerException added):

     
    Thursday, September 04, 2008 8:35 AM
  • OK, I can't read the message in Italian. But seems it's database file access issue (is that right?). Now you know it's not Silverlight or WCF issue.

    Why can you change the DataSource to SQLServer instead of the mdf file? Build your connection string like this:

    string connectionString = "Data Source=YourServerName;Initial Catalog=YourDatabaseInstanceName;User ID=XXX;Password=XXX;"

    In VS, you can use Server Explorer to add a connection:

    1) choose Microsoft SQL Server (SqlClient) as DataSource, choose your db server name,

    2) select Use SQL server authentication. type in userID and password, Test the connection. In the advanced

    3) select the database you want to connect

    4) Test the connection. If it can connect, click the advanced button to see the connection string. Copy that string to your config file.

     

                         

     

    Thursday, September 04, 2008 9:35 AM
  •  Hi,

    i have find the specific problem in english language, is there:

    http://support.microsoft.com/?scid=kb%3Ben-us%3B908038&x=13&y=16

    Thursday, September 04, 2008 10:13 AM
  •  I have modified the string connection with user id= sa and relative password but the problem persist.

    When i change the AttachDbFilename with Initial Catalog= database1.mdf, when i call the method he says denied access for NT AUTORITHY

    Thursday, September 04, 2008 12:08 PM
  • Initial Catalog should be the data base name that under under SQLServer, not the mdf file name. You need to create a Database in your SQLServerExpress, import that mdf file. Then point to the database.

     

    Thursday, September 04, 2008 12:11 PM
  •  For everyone, i have finally solved the problem.

    When i'll have few minutes, i'll write the solution.

     Thanks so much to everybody.

    Friday, September 05, 2008 3:00 PM
  •  i have exactly the same problem

     

    webhorse what did you do to solve it ?

    Friday, October 10, 2008 4:29 AM