We help IT Professionals succeed at work.

WEB SERVICE AT SILVERLIGHT PROJECT

emi_sastra
emi_sastra asked
on
Hi All,

I have a project that use web service.

Should I host the project to run it ?

Thank you.
Comment
Watch Question

In an SilverLight project, If you refernece an webservcie from an webapplication.
you will be able to see an file "ServiceReferences.ClientConfig" in the silverlight project which will have the reference to the service URL which in turn be used by SL application to invoke the servcie

Take a look at the Code project sample on dynamically chnaging the URL based on domain
http://www.codeproject.com/Tips/197520/Dynamically-send-WCF-endpoint-in-Silverlight?display=Print

Author

Commented:
Does it mean we have to create virtual directory for it ?
Follow the example in code project will take care of it, No need to worry about Virtual directory in the development phase.

Author

Commented:
I have a project that use web service and I don't have virtual directory for it.
It seems not work well.
I just want to know if I have to create a virtual directory or not to run the web service ?
I use to consume service in silverlight application with out VD.

check the below info to get more information

Open the file "ServiceReferences.ClientConfig" in the silverlight application and see which URL it's pointing and check whethr the servcie is accessable

Open the "Web.config" in the Servcie application and search for the Servciehost details in config file and check whether the URL is same in both the files.

Author

Commented:
Please see below code :

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IBonous" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
                    <security mode="None" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost/BonousSystem/Bonous.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IBonous"
                contract="BonousService.IBonous" name="BasicHttpBinding_IBonous" />
        </client>
    </system.serviceModel>
</configuration>
Your are tryign to access the servciem which is not histed in IIS as we disabled the option in the previous thread.

If you run the Website, it will run with

http://localhost:<<portnumber>>/BonousSystem , so append the port to the SL ServiceReferences.ClientConfig config file.

Similary in the Web.cong file of the webapplication change the URL with the port number.

Once done the above change and run the application.

Check the codeproject sample to fix the issue permanetly and no need to do this manually changes in future

Author

Commented:
What is the port number ?

Author

Commented:
http://localhost:13616/HRAppTestPage.aspx#/Home

and

file:///D:/EMI%20NEW/APLIKASI%20WEB/BonousSystem/BonousSystem/BonousSystem/Bin/Debug/BonousSystemTestPage.html

Why one has port and another one is not ?

Thank you.
If we have IIS and hosted teh project in IIS, it will use the default port number to host the application, If the IIS is not installed Visual Studio have been come up with the default  Web server take a look in to the MSDN for more info and when it be used

http://msdn.microsoft.com/en-us/library/58wxa9w5.aspx

In this case , we are usign the VS built in server to host the project and which use the available port instead of default port.
when you launch the application you can see an "asp" web server in you windows quick launch tab on right side corner.

to over come all this this, We need to follow the Silverlight application uses the dynamic URL build.which will be the case even in PROD. Means if the SL application doesn't go with the dynamic service url bild it will fail as the URL in the "servciereference.clientconfig" will be pointing to the development.

If you take a look into the deployment step of SL will give more idea
http://learn.iis.net/page.aspx/262/configuring-iis-for-silverlight-applications/

http://www.codeproject.com/Articles/152778/Deploying-Silverlight-with-WCF-Services

will give understanding of the PORT and the dynamic WCF url build for SL application

Author

Commented:
Ok.

In my case what should I do.

  <endpoint address="http://localhost/BonousSystem/Bonous.svc"

What to change and to what ?

Thank you.
In you previous comment, you have give the port as 13616, Just add that to the servcieend points in both the config file

<endpoint address="http://localhost:13616/BonousSystem/Bonous.svc">

Author

Commented:
Below are the web config.

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
        <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
    </system.web>
  <connectionStrings>
    <add name="DB_ConnectionString" connectionString="Data Source=XXX\SQLEXPRESS;Initial Catalog=INF_MLM;Integrated Security=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
</configuration>


Thank you.

Author

Commented:
There is no endpoint at the web config ?

Author

Commented:
Could it be any problem ?

Author

Commented:
Please see below warning.
WEB-SERVICE-WARNING.PNG
give Yes and try

Author

Commented:
I am so sorry, just back again.

Thank you very much for your help.