I found the best way to avoid all these trouble is to change your code to the following to by-pass the url reading in the config file if your web service stays at the same site as your Silverlight page:
Do not rely on the URL set in the 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 will work both in dev and after deploy.
var webService = new YourWebService.YourWebServiceClient("YourServiceEndPointName", address.AbsolutePath);
This way your url will always be correct. The call will not be cross-domain call in all cases, so you avoid a lot of trouble.
Sally Xu
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
OK - that was correct, I could not change the URL until after I moved the webSite to IIS or any host server. So once I moved it I was indeed able to change the endpoint in ServicesReferences.ClientConfig - but that wasn't enough - I still needed to change
the webService address via Configure Service Reference...
So - I think sladapter's way in the long run is more straightforward - and less of a hassel.
namespace YV
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
Uri address = new Uri(Application.Current.Host.Source, "../Service1.svc"); // this url will work both in dev and after deploy.
var webService = new Service1Client("YourServiceEndPointName", address.AbsolutePath);
webService.DoWorkCompleted += new EventHandler<DoWorkCompletedEventArgs>(client_DoWorkCompleted);
webService.DoWorkAsync();
}
Still not right I'm afraid.
The following works just fine if properties/Web/Servers is set to
"Use Visual Studio Development Server"
void Page_Loaded(object sender, RoutedEventArgs e)
{
Uri address = new Uri(Application.Current.Host.Source, "../Service1.svc"); // this url will work both in dev and after deploy.
var webService = new Service1Client("BasicHttpBinding_Service1", address.AbsoluteUri);
webService.DoWorkCompleted += new EventHandler<DoWorkCompletedEventArgs>(client_DoWorkCompleted);
webService.DoWorkAsync();
}
But with fails with "The remote server returned an unexpected response: (404) Not Found."
if properties/Web/Servers is set to
"Use Local IIS Web Server"
I will more than understand if you are fed up with this problem.
Are you having this problem in debug mode or under IIS? What is your page url? If you are get this error when you are running on IIS, you can use Attach process to debug.
You can put a break point at the line: Uri address = new Uri(Application.Current.Host.Source, "../Service1.svc")
First run your page on the browser. Then use Attach to Process(under debug tag) to attach to the IE or Firefox that has your page running. Make sure you select Silverlight Code (not native code, it might be default) in the Attach To box. Then refresh your
page again, you should hit your break point.
Check what is the address.AbsoluteUri. Put this url in a browser and see if you can even hit it from the browser. Let us know what you get.
Sally Xu
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
mebjen
Member
82 Points
101 Posts
VS2008 / SL2B2 - WCF or WebService, Change Configuration ?
Jun 26, 2008 01:32 PM | LINK
When I try to change the address via rightClicking on the ServiceReference and choosing Configure Service Reference... to either a Silverlight-enabled Web Service(.svc) or a Web Service(.asmx) from http://localhost:49547/sl2b2_webServiceTest2Web/servSL2B2.svc to http://localhost/sl2b2_webServiceTest2Web/servSL2B2.svc I get an error saying "There was no endpoint listenting at http://localhost/sl2b2_webServiceTest2Web/servSL2B2.svc that could accept the message".
How are we supposed to change the url prior to building and deploying to IIS?
SteveWong
Contributor
6719 Points
1346 Posts
Re: VS2008 / SL2B2 - WCF or WebService, Change Configuration ?
Jun 26, 2008 03:41 PM | LINK
Did you publish your Webservice onto IIS? and can you access the clientaccesspolicy.xml?
SteveWong (HongKong)
Please mark post as answer if they help you
sladapter
All-Star
43607 Points
7907 Posts
Re: VS2008 / SL2B2 - WCF or WebService, Change Configuration ?
Jun 26, 2008 03:51 PM | LINK
If you have not make your website to the IIS yet, you certainly can not change the service url at this point by using http://localhost/sl2b2_webServiceTest2Web/servSL2B2.svc
I found the best way to avoid all these trouble is to change your code to the following to by-pass the url reading in the config file if your web service stays at the same site as your Silverlight page:
Do not rely on the URL set in the 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 will work both in dev and after deploy.
var webService = new YourWebService.YourWebServiceClient("YourServiceEndPointName", address.AbsolutePath);
This way your url will always be correct. The call will not be cross-domain call in all cases, so you avoid a lot of trouble.
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
mebjen
Member
82 Points
101 Posts
Re: VS2008 / SL2B2 - WCF or WebService, Change Configuration ?
Jun 27, 2008 01:06 PM | LINK
OK - that was correct, I could not change the URL until after I moved the webSite to IIS or any host server. So once I moved it I was indeed able to change the endpoint in ServicesReferences.ClientConfig - but that wasn't enough - I still needed to change the webService address via Configure Service Reference...
So - I think sladapter's way in the long run is more straightforward - and less of a hassel.
Thanks again -sladapter
meerkatinfrance
Member
27 Points
66 Posts
Re: Re: VS2008 / SL2B2 - WCF or WebService, Change Configuration ?
Jun 27, 2008 05:13 PM | LINK
Hello again sladapter,
I am really sorry for being thick, but I cannot get it to work
Whatever string I put in "YourServiceEndPointName", I get "Invalid URI: The format of the URI could not be determined."
( I tried every possible string including "BasicHttpBinding_Service1")
Shown below are the relevant files. Could I impose on your kindness one more time and ask what I should replace "YourServiceEndPointName" with.
Thanking you for your patience,
Pete.
ServicesReferences.Config
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_Service1" maxBufferSize="65536"
maxReceivedMessageSize="65536">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:49720/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_Service1" contract="YV.ServiceReference1.Service1"
name="BasicHttpBinding_Service1" />
</client>
</system.serviceModel>
</configuration>
Page.xaml.cs
using YV.ServiceReference1;
namespace YV
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
Uri address = new Uri(Application.Current.Host.Source, "../Service1.svc"); // this url will work both in dev and after deploy.
var webService = new Service1Client("YourServiceEndPointName", address.AbsolutePath);
webService.DoWorkCompleted += new EventHandler<DoWorkCompletedEventArgs>(client_DoWorkCompleted);
webService.DoWorkAsync();
}
void client_DoWorkCompleted(object sender, DoWorkCompletedEventArgs e)
{
txtBlock.Text = e.Result;
}
}
}
sladapter
All-Star
43607 Points
7907 Posts
Re: Re: VS2008 / SL2B2 - WCF or WebService, Change Configuration ?
Jun 27, 2008 05:22 PM | LINK
Sorry, it should be:
var webService = new Service1Client("BasicHttpBinding_Service1", address.AbsoluteUri);
I thought I changed that in one of my post.
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
meerkatinfrance
Member
27 Points
66 Posts
Re: Re: Re: VS2008 / SL2B2 - WCF or WebService, Change Configuration ?
Jun 27, 2008 05:55 PM | LINK
Hello sladapter
Still not right I'm afraid.
The following works just fine if properties/Web/Servers is set to
"Use Visual Studio Development Server"
void Page_Loaded(object sender, RoutedEventArgs e)
{
Uri address = new Uri(Application.Current.Host.Source, "../Service1.svc"); // this url will work both in dev and after deploy.
var webService = new Service1Client("BasicHttpBinding_Service1", address.AbsoluteUri);
webService.DoWorkCompleted += new EventHandler<DoWorkCompletedEventArgs>(client_DoWorkCompleted);
webService.DoWorkAsync();
}
But with fails with "The remote server returned an unexpected response: (404) Not Found."
if properties/Web/Servers is set to
"Use Local IIS Web Server"
I will more than understand if you are fed up with this problem.
Fingers crossed for a reply though,
Regards,
Pete.
sladapter
All-Star
43607 Points
7907 Posts
Re: Re: Re: VS2008 / SL2B2 - WCF or WebService, Change Configuration ?
Jun 27, 2008 06:21 PM | LINK
Are you having this problem in debug mode or under IIS? What is your page url? If you are get this error when you are running on IIS, you can use Attach process to debug.
You can put a break point at the line: Uri address = new Uri(Application.Current.Host.Source, "../Service1.svc")
First run your page on the browser. Then use Attach to Process(under debug tag) to attach to the IE or Firefox that has your page running. Make sure you select Silverlight Code (not native code, it might be default) in the Attach To box. Then refresh your page again, you should hit your break point.
Check what is the address.AbsoluteUri. Put this url in a browser and see if you can even hit it from the browser. Let us know what you get.
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question